From: Zygo Blaxell Date: Fri, 14 Aug 2026 04:09:27 +0000 (-0400) Subject: trace: work around GCC -Wmaybe-uninitialized bug in BEESTRACE X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;p=bees 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: '' 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 --- diff --git a/src/bees.h b/src/bees.h index 7c0cfca5..71adb5a9 100644 --- a/src/bees.h +++ b/src/bees.h @@ -129,7 +129,7 @@ const int FLAGS_CREATE_FILE = FLAGS_OPEN_COMMON | O_RDWR | O_CREAT | O_EXCL; #define BEESLOG(lv,x) do { if (lv < bees_log_level) { Chatter __chatter(lv, BeesNote::get_name()); __chatter << x; } } while (0) extern int bees_trace_level; -#define BEESTRACE(x) BeesTracer SRSLY_WTF_C(beesTracer_, __LINE__) ([&]() { BEESLOG(bees_trace_level, "TRACE: " << x << " at " << __FILE__ << ":" << __LINE__); }) +#define BEESTRACE(x) BeesTracer SRSLY_WTF_C(beesTracer_, __LINE__) ([&, __func = __FUNCTION__]() { BEESLOG(bees_trace_level, "TRACE: " << __func << ": " << x << " at " << __FILE__ << ":" << __LINE__); }) #define BEESTOOLONG(x) BeesTooLong SRSLY_WTF_C(beesTooLong_, __LINE__) ([&](ostream &_btl_os) { _btl_os << x; }) #define BEESNOTE(x) BeesNote SRSLY_WTF_C(beesNote_, __LINE__) ([&](ostream &_btl_os) { _btl_os << x; })