我正在使用 gcc 和 libc++ (llvm) 运行构建。自从更新到 Debian Bookworm 后,我得到:
/usr/lib/llvm-14/include/c++/v1/regex:1384:8: warning: ‘<unnamed>.std::__1::__state<char>::__at_first_’ may be used uninitialized [-Wmaybe-uninitialized]
(以及许多其他日志)
我已将问题简化为以下示例:
示例.cpp:
#include <regex>
int doIt()
{
std::regex r("bla");
return 0;
}
编译器调用:
/usr/bin/g++ -Wmaybe-uninitialized -O1 -nostdinc++ -isystem /usr/lib/llvm-14/include/c++/v1/ -c example.cpp
需要的apt包:g++、libc++-14-dev
当我删除优化(
-O1
)时,问题就消失了。如果我使用此列表中的所有单独优化,问题就消失了。当我使用不带参数的 std::regex
构造函数时,问题就消失了。
问题:
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
添加到 <regex>
的所有包含内容中的情况下解决此问题?使用WSL2 Debian Bookworm,确认了同样的问题。
似乎是
__at_first_
未在 LLVM 中初始化的小问题
因为
~$> sudo sed -i 's/ __node_(nullptr), __flags_() {}/ __node_(nullptr), __flags_(),__at_first_(false) {}/' /usr/lib/llvm-14/include/c++/v1/regex
允许您用于按预期进行编译的构建命令:
~$> /usr/bin/g++ -Wmaybe-uninitialized -O1 -nostdinc++ -isystem /usr/lib/llvm-14/include/c++/v1/ -c example.cpp
~$>
但是,对我来说,它无法访问 iostream,因此在构建之前没有打印任何内容:
~$> /usr/bin/g++ -Wmaybe-uninitialized -O1 example.cpp
~$> ./a.out
Text contains the phrase 'regular expressions'
Found 20 words
...