https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122740

            Bug ID: 122740
           Summary: internal compiler error: crash at cp/call.cc:8712 when
                    union has reference member initialized with literal
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: ice-checking, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: attackerj1113 at gmail dot com
  Target Milestone: ---

The following code causes ICE out on x86-64 gcc since version 15.1(assertions)
and reproducible on trunk:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename T>
class A {
public:
  A(T){}
};

union Test {
  const int& k = 10;
};

A w = A{Test{}};

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Clang/EDG report the error correctly, but MSVC also triggers an ICE.

Please check https://godbolt.org/z/sTdTvoMjE

A union containing a const int& member initialized with a literal expression
triggers an ICE in convert_like_internal during compound literal construction.

Compiler Output:
<source>:8:14: error: non-static data member 'Test::k' in a union may not have
reference type 'const int&'
    8 |   const int& k = 10;
      |              ^
<source>:11:14: internal compiler error: in convert_like_internal, at
cp/call.cc:8712
   11 | A w = A{Test{}};
      |              ^
0x29109c8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x290578b internal_error(char const*, ...)
        ???:0
0xb0d332 fancy_abort(char const*, int, char const*)
        ???:0
0xb457ce initialize_reference(tree_node*, tree_node*, int, int)
        ???:0
0xe29080 convert_for_initialization(tree_node*, tree_node*, tree_node*, int,
impl_conv_rhs, tree_node*, int, int)
        ???:0
0xdcbabb finish_compound_literal(tree_node*, tree_node*, int, fcl_t)
        ???:0
0xd475a3 c_parse_file()
        ???:0
0xeb6639 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.
Compiler returned: 1

Reply via email to