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

            Bug ID: 123688
           Summary: [14/15/16 Regression] ICE in
                    template_heads_equivalent_p (tree check: expected
                    template_decl, have template_template_parm) during
                    mangling of lambda with requirements
           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/n8Phfx1qf
The following c++ code crash gcc trunk with -std=c++20 flag.
Goes back to 14.1 with checking.

Code:
```cpp
template <int D>
struct S_Base {
    static constexpr int D_val = D;
};
template <typename T>
struct S_Derived : S_Base<T::value> {
    using S_Base<T::value>::D_val;
};
template <class, class> class C
{
};
template <template<class,class=int> class C, class T> void g(C<T> c)
{
    struct Config;
    auto constrained_func = []() requires (S_Derived<Config>::D_val > 0) {};
}
int main()
{
  C<int,int> c;
  g(c);
}
```

Stack dump:
```
<source>: In instantiation of 'struct S_Derived<g<C, int>(C<int,
int>)::Config>':
required from 'g<C, int>(C<int, int>)::<lambda()>'
<source>:15:63:   
   15 |     auto constrained_func = []() requires (S_Derived<Config>::D_val >
0) {};
      |                                                               ^~~~~
required from 'void g(C<T>) [with C = C; T = int]'
<source>:15:29:   
   15 |     auto constrained_func = []() requires (S_Derived<Config>::D_val >
0) {};
      |                            
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
required from here
<source>:20:4:   
   20 |   g(c);
      |   ~^~~
<source>:6:8: error: incomplete type 'g<C, int>(C<int, int>)::Config' used in
nested name specifier
    6 | struct S_Derived : S_Base<T::value> {
      |        ^~~~~~~~~
<source>:7:29: error: incomplete type 'g<C, int>(C<int, int>)::Config' used in
nested name specifier
    7 |     using S_Base<T::value>::D_val;
      |                             ^~~~~
<source>:15:29: internal compiler error: tree check: expected template_decl,
have template_template_parm in template_heads_equivalent_p, at cp/pt.cc:3548
   15 |     auto constrained_func = []() requires (S_Derived<Config>::D_val >
0) {};
      |                             ^
0x2950b58 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x294591b internal_error(char const*, ...)
        ???:0
0xa2350f tree_check_failed(tree_node const*, char const*, int, char const*,
...)
        ???:0
0xc80cc9 mangle_decl(tree_node*)
        ???:0
0x18c3645 decl_assembler_name(tree_node*)
        ???:0
0xfca176 symbol_table::finalize_compilation_unit()
        ???: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