https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113306
Bug ID: 113306 Summary: constexpr cast from void* fails with typeid result target Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pkeir at outlook dot com Target Milestone: --- The C++26 code below fails to compile with GCC trunk; with Clang it passes. The error message indicates that the constexpr evaluator uses `const __fundamental_type_info_pseudo_2` as the type of `typeid(int)`. (See https://godbolt.org/z/1Mr9ao9hr.) #include <typeinfo> #include <cassert> constexpr bool test1() { const void* cvp = &typeid(int); return static_cast<const std::type_info*>(cvp) != nullptr; } int main(int argc, char *argv[]) { static_assert(test1()); assert(test1()); return 0; } The error message is below. bug3.cpp:13:22: in ‘constexpr’ expansion of ‘test1()’ bug3.cpp:8:10: error: cast from ‘const void*’ is not allowed in a constant expression because pointed-to type ‘const __fundamental_type_info_pseudo_2’ is not similar to ‘const std::type_info’ 8 | return static_cast<const std::type_info*>(cvp) != nullptr; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bug3.cpp:6:32: note: pointed-to object declared here 6 | const void* cvp = &typeid(int);