https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105616
Donn Seeley <donn.seeley at everfox dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |donn.seeley at everfox dot com
--- Comment #6 from Donn Seeley <donn.seeley at everfox dot com> ---
I'm seeing this problem in GCC 14.2.1. I'm trying to put together automated
ASAN testing for our product, and it's very annoying. The problem isn't
exclusive to <regex>.
Here's my simple reproducer:
#include <string>
#include <regex>
std::regex re{"x"};
std::string x2y(const std::string& s)
{
return std::regex_replace(s, re, "y");
}
I build it with:
g++ -std=gnu++17 -O2 -fsanitize=address -Werror -Wall -Wextra -c
regex_bug.cpp
It produces the same set of error messages as the OP. I can include the full
blast of messages if anyone's interested. The failure occurs with -O1 and
higher optimization levels, but not -O0.
After I found that the problem doesn't appear when building with -O0, I did
some bisection to identify the optimizations that trigger the problem. I can
build the test program successfully with:
g++ -std=gnu++17 -O1 -fsanitize=address -fno-tree-dominator-opts
-fno-tree-fre -Werror -Wall -Wextra -c regex_bug.cpp
or
g++ -std=gnu++17 -O2 -fsanitize=address -fno-code-hoisting
-fno-tree-dominator-opts -fno-tree-fre -fno-tree-pre -Werror -Wall -Wextra -c
regex_bug.cpp
For now, I have added "#pragma GCC optimize (0)" directives for "#include
<regex>" in our source code.