https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962
Bjorn Pagen <hello at bjornpagen dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hello at bjornpagen dot com
--- Comment #20 from Bjorn Pagen <hello at bjornpagen dot com> ---
This bug also affects C++26 reflection and consteval code in GCC 16.1.0.
This standalone testcase reproduces the std::string(ptr, size) failure over
vague-linkage storage:
#include <string>
inline constexpr char text[] = "x";
consteval auto check() -> bool {
auto value = std::string{text, 1};
return value == "x";
}
static_assert(check());
Command:
g++-16 -std=c++26 -fsanitize=undefined -c repro.cc
GCC rejects the static assertion. The final diagnostic is:
bits/basic_string.h:713:17: error: '(((const char*)(& text)) == 0)' is not a
constant expression
The same command succeeds without -fsanitize=undefined.
Reflection APIs can expose text through compiler-generated storage with the
same linkage property. This bug therefore blocks required constant evaluation
in reflection code.
Attachment 65251, added on 2026-08-05, addresses the same separation between
constant evaluation and null-check optimization. This testcase can extend its
regression coverage.