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

--- Comment #1 from Jireh Guo <jirehguo at tju dot edu.cn> ---
Compiler Explorer: https://godbolt.org/z/eEj1jEo8q
The following c++ code crash gcc trunk.

Code:
```cpp
#include <string>

struct MergedObject {
  std::string str;
  int value;

  MergedObject(const std::string &s) : str(s), value(0) {}
};


int main() {
    auto stage3 = [&](auto &&...args) {
        auto stage3_1 = [&](auto &&...innerArgs) {
          auto stage3_1_1 = [&](auto &&...innerInnerArgs) {
            union {
              MergedObject obj1;
              MergedObject obj2;
            };
            ::new (&obj1) MergedObject("Hello");
          };
          stage3_1_1();
        };
        stage3_1();
      };
      stage3();
}

```

Stack dump:
```
<source>: In instantiation of 'main()::<lambda(auto:6&& ...)> [with auto:6 =
{}]':
required from here
<source>:25:13:   
   25 |       stage3();
      |       ~~~~~~^~
<source>:18:13: error: using invalid field 'main()::<lambda(auto:6&&
...)>::<lambda(auto:7&& ...)>::<lambda(auto:8&& ...)>::<unnamed union>::obj1'
   18 |             };
      |             ^
<source>:18:13: internal compiler error: tree check: expected class 'type',
have 'exceptional' (error_mark) in tsubst_decl, at cp/pt.cc:16049
0x291af48 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x290fd0b internal_error(char const*, ...)
        ???:0
0xa18d12 tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
        ???:0
0xb50fbc tree_class_check(tree_node*, tree_code_class, char const*, int, char
const*)
        ???:0
0xd94f6b tsubst_tree_list(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xd7e2d5 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xd7e2d5 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xdb63dd instantiate_decl(tree_node*, bool, bool)
        ???:0
0xc29493 maybe_instantiate_decl(tree_node*)
        ???:0
0xc2b2b7 mark_used(tree_node*, int)
        ???:0
0xb50e33 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        ???:0
0xddb665 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xd542e3 c_parse_file()
        ???:0
0xec5d19 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