gcc-14: warning: ‘<anonymous>’ may be used uninitialized
Gentoo emits the following warning when building the package:
In member function ‘__ct ’,
inlined from ‘__ct ’ at bees-trace.cc:47:2,
inlined from ‘operator()’ at bees-roots.cc:1743:4,
inlined from ‘__invoke_impl’ at /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/invoke.h:61:36,
inlined from ‘__invoke_r’ at /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/invoke.h:150:33,
inlined from ‘_M_invoke’ at /usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/std_function.h:290:30:
/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/std_function.h:391:17: warning: ‘<anonymous>’ may be used uninitialized [-Wmaybe-uninitialized]
391 | __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
| ^
/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/std_function.h: In function ‘_M_invoke’:
/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/g++-v14/bits/std_function.h:267:7: note: by argument 2 of type ‘const union _Any_data & {ref-all}’ to ‘_M_manager’ declared here
267 | _M_manager(_Any_data& __dest, const _Any_data& __source,
| ^
bees-roots.cc:1743:25: note: ‘<anonymous>’ declared here
1743 | BEESTRACE("calling transid_max_nocache");
| ^
This is probably another instance of newer gcc versions showing spurious warnings but I just wanted to report that in case it is something that should be fixed.
Thanks.
Yeah, gcc -Wmaybe-uninitialized is notorious for false positives, and I almost always turn it off. The other option is to randomly initialize some variable that you know can never be used uninitialized, only to silence gcc, but that obfuscates the code. (In that case, a comment about gcc's warning is appropriate.)
That said, here it is complaining about an internal detail of gcc's own std::function implementation, so this may very well be a bug in gcc itself.
Note that with gcc-13 this warning does not appear. So gcc-14 maybe got more aggressive with this warning. But it could also be a bug in gcc 14's libstdc++...
In any case, for my own build I use:
--- a/makeflags
+++ b/makeflags
@@ -10,4 +10,4 @@ CCFLAGS = -Wall -Wextra -Werror -O3
CCFLAGS += -I../include -D_FILE_OFFSET_BITS=64
BEES_CFLAGS = $(CCFLAGS) -std=c99 $(CFLAGS)
-BEES_CXXFLAGS = $(CCFLAGS) -std=c++11 -Wold-style-cast -Wno-missing-field-initializers $(CXXFLAGS)
+BEES_CXXFLAGS = $(CCFLAGS) -std=c++11 -Wold-style-cast -Wno-missing-field-initializers -Wno-maybe-uninitialized $(CXXFLAGS)
Btw, which version of gcc-14 did you use? I'm using gcc version 14.2.0 (Ubuntu 14.2.0-4ubuntu2~24.04), and this does not produce the maybe-uninitialized warning, even after removing all the -Wno-xxx flags.
Note that GCC releases have historically alternated between working and not working. Or at least the last four did.