https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103299
Bug ID: 103299 Summary: accessing incorrect storage for union at constexpr context Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: unlvsur at live dot com Target Milestone: --- struct compile_time_fp { void* ct_fp{}; }; struct foo { union { void* fp{}; compile_time_fp ct_fp; }; }; inline constexpr foo foo_factory() { if (__builtin_is_constant_evaluated()) { return {.ct_fp={}}; } else { return {}; } } constexpr bool test_direct_construction() { foo f{.ct_fp={}}; f.ct_fp; return true; } constexpr bool test_factory_construction() { foo_factory().ct_fp; return true; } static_assert(test_direct_construction()); static_assert(test_factory_construction());//should not fail GCC fails for the 2nd one while msvc and clang all accept the code here.