I am running a build with gcc and libc++ (llvm). Since update to debian bookworm I get:
/usr/lib/llvm-14/include/c++/v1/regex:1384:8: warning: ‘<unnamed>.std::__1::__state<char>::__at_first_’ may be used uninitialized [-Wmaybe-uninitialized]
(along with a lot of other logs)
I have dumbed the problem down to this example:
example.cpp:
#include <regex>
int doIt()
{
std::regex r("bla");
return 0;
}
compiler call:
/usr/bin/g++ -Wmaybe-uninitialized -O1 -nostdinc++ -isystem /usr/lib/llvm-14/include/c++/v1/ -c example.cpp
Needed apt packages: g++, libc++-14-dev
When I remove the optimization (-O1), then the issue is gone. If I use all the separate optimizations from this list, the issue is gone. When i use the std::regex constructor with no args, the issue is gone.
Questions:
- Am I doing something wrong with compiler settings?
- Is this a bug? Is it a bug for gcc or libc++?
- How can I fix this without adding
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"to all includes of<regex>?
Using WSL2 Debian Bookworm, confirmed the same issue.
Seems to be a minor issue of
__at_first_not being initialized in LLVM athttps://github.com/llvm/llvm-project/blob/17fc78e7a4e178482650f2a1c18954823c5cd4eb/libcxx/include/regex#L1462
because
allowed the build command you used to compile as expected:
However, for me, linking was only possible with: