https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123571
Bug ID: 123571
Summary: ICE Segmentation fault in tsubst/tsubst_lambda_expr
with friend declaration inside local class within a
lambda-template-parameter
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/59K9MYrss
The following c++ code crash gcc trunk.
And goes back to gcc 12.1 with checking.
Code:
```cpp
template <int N>
void foo(char (*s)[([] {
class LocalClass {
public:
friend void func();
};
})]) {}
int main() { foo<1>(nullptr); }
```
Stack dump:
```
<source>: In lambda function:
<source>:3:20: error: types may not be defined in parameter types
[-Wtemplate-body]
3 | class LocalClass {
| ^
<source>: In substitution of 'template<int N> void foo(char (*)[<lambda>])
[with int N = 1]':
required from here
<source>:8:20:
8 | int main() { foo<1>(nullptr); }
| ~~~~~~^~~~~~~~~
<source>:3:9: error: 'func' was not declared in this scope
3 | class LocalClass {
| ^~~~~~~~~~
<source>: In instantiation of 'class<lambda()>::LocalClass':
required by substitution of 'template<int N> void foo(char (*)[<lambda>]) [with
int N = 1]'
<source>:6:3:
6 | };
| ^
required from here
<source>:8:20:
8 | int main() { foo<1>(nullptr); }
| ~~~~~~^~~~~~~~~
<source>:5:17: internal compiler error: Segmentation fault
5 | friend void func();
| ^~~~
0x2924328 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x29190eb internal_error(char const*, ...)
???:0
0xd8f442 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0xdc0adc instantiate_class_template(tree_node*)
???:0
0xd80e05 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
???:0
0xd8ea07 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0xd8eaa2 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0xd8f7ab tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0xd8ec0f tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0xdaad4d instantiate_template(tree_node*, tree_node*, int)
???:0
0xdbbfca fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
???:0
0xb4ec09 build_new_function_call(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xdddc25 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
???:0
0xd56dd3 c_parse_file()
???:0
0xec8829 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
```