https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116741
Bug ID: 116741 Summary: ICE with invalid cast from void* in constexpr Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nshead at gcc dot gnu.org Target Milestone: --- The following sample: struct S { int foo; }; constexpr float f() { S s; void* p = &s.foo; return *static_cast<float*>(p); } constexpr auto x = f(); fails on trunk (-std=c++26) with: test.cpp:11:21: in ‘constexpr’ expansion of ‘f()’ test.cpp:8:11: error: cast from ‘void*’ is not allowed in a constant expression because pointed-to type ‘int’ is not similar to ‘float’ 8 | return *static_cast<float*>(p); | ^~~~~~~~~~~~~~~~~~~~~~ test.cpp:8:11: internal compiler error: tree check: expected tree that contains ‘decl minimal’ structure, have ‘component_ref’ in cxx_eval_constant_expression, at cp/constexpr.cc:8203 0x3ad6512 internal_error(char const*, ...) ../../gcc/gcc/diagnostic-global-context.cc:517 0x2098f8c tree_contains_struct_check_failed(tree_node const*, tree_node_structure_enum, char const*, int, char const*) ../../gcc/gcc/tree.cc:9177 0xe39100 contains_struct_check(tree_node*, tree_node_structure_enum, char const*, int, char const*) ../../gcc/gcc/tree.h:3779 0xed6f78 cxx_eval_constant_expression ../../gcc/gcc/cp/constexpr.cc:8203 0xecd1b4 cxx_eval_indirect_ref ../../gcc/gcc/cp/constexpr.cc:5926 0xed5b9a cxx_eval_constant_expression ../../gcc/gcc/cp/constexpr.cc:7849 0xecf2a4 cxx_eval_store_expression ../../gcc/gcc/cp/constexpr.cc:6238 0xed53c6 cxx_eval_constant_expression ../../gcc/gcc/cp/constexpr.cc:7719 0xed54b5 cxx_eval_constant_expression ../../gcc/gcc/cp/constexpr.cc:7731 0xed2408 cxx_eval_statement_list ../../gcc/gcc/cp/constexpr.cc:6991 0xed8144 cxx_eval_constant_expression ../../gcc/gcc/cp/constexpr.cc:8362 0xed827f cxx_eval_constant_expression ../../gcc/gcc/cp/constexpr.cc:8371 0xec1e63 cxx_eval_call_expression ../../gcc/gcc/cp/constexpr.cc:3300 0xed4622 cxx_eval_constant_expression ../../gcc/gcc/cp/constexpr.cc:7566 0xeda8e7 cxx_eval_outermost_constant_expr ../../gcc/gcc/cp/constexpr.cc:8852 0xedc479 maybe_constant_init_1 ../../gcc/gcc/cp/constexpr.cc:9363 0xedc537 cxx_constant_init(tree_node*, tree_node*) ../../gcc/gcc/cp/constexpr.cc:9389 0x12eda97 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) ../../gcc/gcc/cp/typeck2.cc:909 0xf79ee0 check_initializer ../../gcc/gcc/cp/decl.cc:7870 0xf80ccc cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int, cp_decomp*) ../../gcc/gcc/cp/decl.cc:8918 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.