https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962
Mateusz Pusz <mateusz.pusz at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mateusz.pusz at gmail dot com
--- Comment #25 from Mateusz Pusz <mateusz.pusz at gmail dot com> ---
Still fails on trunk (gcc version 17.0.0 20261202), and in 12.5, 13.4, 14.3,
15.2 and a 16 snapshot (16-20260322). This is the variable-template case from
comment 23, reached through consteval functions as in code that compares types
by address:
template<class T> inline constexpr char token{};
struct id { const void* t; };
template<class T> consteval id mk() { return {&token<T>}; }
consteval bool eq(id a, id b) { return a.t == b.t; }
static_assert(eq(mk<int>(), mk<int>()));
static_assert(!eq(mk<int>(), mk<long>()));
int main() {}
$ g++ -std=c++23 -fsanitize=null -c t.cpp
t.cpp:6:15: error: non-constant condition for static assertion
6 | static_assert(!eq(mk<int>(), mk<long>()));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
t.cpp:4:44: error: '(((const void*)(& token<int>)) == ((const void*)(&
token<long int>)))' is not a constant expression
4 | consteval bool eq(id a, id b) { return a.t == b.t; }
| ~~~~^~~~~~
GCC 12 and 13 print one error instead of two. The same happens with
-fsanitize=undefined, -fsanitize=nonnull-attribute,
-fsanitize=returns-nonnull-attribute and -fno-delete-null-pointer-checks;
-fsanitize=vptr and -fsanitize=bounds alone compile it, as does
-fsanitize=undefined
-fno-sanitize=null,nonnull-attribute,returns-nonnull-attribute. Clang 17 to 23
and trunk accept it with -fsanitize=undefined.
Expected: both static_asserts hold, since token<int> and token<long> are
distinct objects. Comparing the addresses of variable template specializations
is a cheap, standard way to compare types in consteval code, so a library that
does it stops compiling under -fsanitize=undefined.
https://godbolt.org/z/v8YfbdnnG (GCC trunk with no options, -fsanitize=null and
-fno-delete-null-pointer-checks; Clang trunk with -fsanitize=undefined)