]> git.hungrycats.org Git - bees/commit
trace: work around GCC -Wmaybe-uninitialized bug in BEESTRACE master
authorZygo Blaxell <bees@furryterror.org>
Fri, 14 Aug 2026 04:09:27 +0000 (00:09 -0400)
committerZygo Blaxell <bees@furryterror.org>
Tue, 6 Oct 2026 05:30:56 +0000 (01:30 -0400)
commit3414e382dd4112b99c95a3d7c302f51002c30b32
tree1cb3edccbbb494501106bf32e2d373fe983dac60
parent00bd4e5799c39d018efd7cd20d70580f761ebb46
trace: work around GCC -Wmaybe-uninitialized bug in BEESTRACE

When the BEESTRACE message is a plain string literal, the lambda captures
nothing, so the std::function built from it has an empty target.
libstdc++ deliberately leaves the _Any_data union unwritten in that case,
but GCC's optimizer does not know that, and reports the copy made by
BeesTracer's constructor as a read of an uninitialized value:

/usr/include/c++/14/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);

The warning also needs the enclosing scope to be reached through another
std::function, so that the whole call chain collapses into one frame.
Exactly one site in the tree qualifies:  the BEESTRACE with a literal
message inside the catch_all() lambda in BeesRoots::crawl_thread().

Inlining across the bees-trace.cc and bees-roots.cc boundary additionally
requires link-time optimization, so only distributions that add -flto are
affected -- but since -Werror is always on, those builds fail outright
and produce no binary at all.

Give the lambda an init-capture of __FUNCTION__ and print it.  The
closure is no longer empty, the union is visibly initialized, and the
warning goes away.  Trace lines gain the name of the function they came
from, matching the format already used on the development branch.

Verified with GCC 14.2.0, with and without -flto=auto, both with -Werror.

Resolves: https://github.com/Zygo/bees/issues/315
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees.h