https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114706
Bug ID: 114706
Summary: ICE - std::bit_cast in consteval function involving
union
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: cuzdav at gmail dot com
Target Milestone: ---
ICE in a consteval function bit_casting an array of unions. The code isn't
valid due to the union, but the compiler is not handling it properly (since
gcc11...trunk). Reduced to the following program:
CODE
#include <bit>
union U { int u; };
consteval void f() {
U result[]{0, 0};
auto x = std::bit_cast<long>(result);
}
int main() { f(); }
LIVE:
https://godbolt.org/z/Y943bc5zK
OUTPUT
/opt/compiler-explorer/gcc-trunk-20240412/include/c++/14.0.1/bit:94:33:
internal compiler error: in native_encode_initializer, at fold-const.cc:8468
94 | return __builtin_bit_cast(_To, __from);
| ^~~
0x267826c internal_error(char const*, ...)
???:0
0xa58c63 fancy_abort(char const*, int, char const*)
???:0
0xfa0eaf native_encode_initializer(tree_node*, unsigned char*, int, int,
unsigned char*)
???:0
0xacf0f0 maybe_constant_value(tree_node*, tree_node*, mce_value)
???:0
0xd3a75f store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xb474fe cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
???:0
0xc5c81a c_parse_file()
???:0
0xdb1489 c_common_parse_file()
???:0
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.