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

            Bug ID: 123360
           Summary: ICE: tree check: expected class ‘type’, have
                    ‘declaration’ (function_decl) in cp_type_quals, at
                    cp/typeck.cc during reshape_init with nested anonymous
                    compound literal
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 522024330006 at smail dot nju.edu.cn
  Target Milestone: ---

Reproducer: https://godbolt.org/z/xsd86WMjW

A C++ ICE occurs when initializing a structure containing nested anonymous
structs/unions using a C-style compound literal that defines a new anonymous
type. The crash happens in cp_type_quals at cp/typeck.cc because the compiler
encounters a FUNCTION_DECL where it expects a TYPE node during the
initialization reshaping process.

Program:
```
struct Outer {
    struct {
        union {
            int i;
        };
    };
};

int main() {
    Outer outer2 = { (struct { union { int i; }; }) {.i = 0} };
}
```
Traceback:
```
internal compiler error: tree check: expected class 'type', have 'declaration'
(function_decl) in cp_type_quals, at cp/typeck.cc:11951
   12 |     Outer outer2 = { (struct { union { int i; }; }) {.i = 0} };
      |                                                            ^
0x290fae8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x29048ab internal_error(char const*, ...)
        ???:0
0xa17be8 tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
        ???:0
0xe125ff cp_build_qualified_type(tree_node*, int, int)
        ???:0
0xe21bbf same_type_ignoring_top_level_qualifiers_p(tree_node*, tree_node*)
        ???:0
0xc13cd4 reshape_init(tree_node*, tree_node*, int)
        ???:0
0xdd7a23 finish_compound_literal(tree_node*, tree_node*, int, fcl_t)
        ???:0
0xd52ed3 c_parse_file()
        ???:0
0xec4909 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