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

            Bug ID: 123567
           Summary: [16 Regression] ICE in instantiate_decl, at
                    cp/pt.cc:28272
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jirehguo at tju dot edu.cn
  Target Milestone: ---

Compiler Explorer: https://godbolt.org/z/3c4Wroebn
The following c++ code crash gcc trunk.
But 13,14,15 with checking is fine.

Code:
```cpp
template <auto =
              [] {
                class LocalClass {
                  void test();
                };
                LocalClass lc;
                lc.test();
              }>
constexpr bool flag = true;
template <typename> void f() { if constexpr (flag<>) }
int main() { f<int>(); }
```

Stack dump:
```
<source>: In function 'void f()':
<source>:10:54: error: expected primary-expression before '}' token
[-Wtemplate-body]
   10 | template <typename> void f() { if constexpr (flag<>) }
      |                                                      ^
<source>: In instantiation of 'void<lambda()>::LocalClass::test()':
required from 'void f() [with <template-parameter-1-1> = int]'
<source>:7:24:   
    7 |                 lc.test();
      |                 ~~~~~~~^~
required from here
<source>:11:20:   
   11 | int main() { f<int>(); }
      |              ~~~~~~^~
<source>:7:24: internal compiler error: in instantiate_decl, at cp/pt.cc:28272
    7 |                 lc.test();
      |                 ~~~~~~~^~
0x2926688 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x291b44b internal_error(char const*, ...)
        ???:0
0xb16d54 fancy_abort(char const*, int, char const*)
        ???:0
0xc2e0cf mark_used(tree_node*, int)
        ???:0
0xd81555 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xd9bce9 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
        ???:0
0xdb965d instantiate_decl(tree_node*, bool, bool)
        ???:0
0xdc306a instantiate_pending_templates(int)
        ???:0
0xc32a28 c_parse_final_cleanups()
        ???:0
0xec8f18 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