https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123665
Bug ID: 123665
Summary: [15/16 Regression] ICE (Segmentation fault) during
substitution of lambda in template default argument
within recursive generic lambda
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/6YqMdb8Yz
The following c++ code crash gcc trunk with -std=c++23 flag.
And goes back to gcc 15.1 with checking.
Clang and gcc 14.3 accepts it, but gcc 14.1, 14.2 reject.
Code:
```cpp
template <typename = decltype([](auto) {})> struct ComplexTemplate;
template <typename> void h() {
auto recurse = [](auto, int) {
using TemplateResult = ComplexTemplate<>;
};
recurse(recurse, 5);
}
struct foo {
foo() { h<int>; }
};
```
Stack dump:
```
<source>: In instantiation of 'h<int>()::<lambda(auto:2, int)> [with auto:2 =
h<int>()::<lambda(auto:2, int)>]':
required from 'void h() [with <template-parameter-1-1> = int]'
<source>:6:10:
6 | recurse(recurse, 5);
| ~~~~~~~^~~~~~~~~~~~
required from here
<source>:9:17:
9 | foo() { h<int>; }
| ^
<source>:1:31: internal compiler error: Segmentation fault
1 | template <typename = decltype([](auto) {})> struct ComplexTemplate;
| ^~~~~~~~~~~
0x2950a78 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x294583b internal_error(char const*, ...)
???:0
0xd76e81 template_parms_to_args(tree_node*)
???:0
0xd8ee23 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
???:0
0xd9d8f1 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0xdaa249 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
???:0
0xd9dbb3 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0xd9df92 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0xdc7c3d instantiate_decl(tree_node*, bool, bool)
???:0
0xc36823 maybe_instantiate_decl(tree_node*)
???:0
0xc387e7 mark_used(tree_node*, int)
???:0
0xb5c0b3 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
???:0
0xe03535 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
???:0
0xdc7c3d instantiate_decl(tree_node*, bool, bool)
???:0
0xdd177a instantiate_pending_templates(int)
???:0
0xc3cd58 c_parse_final_cleanups()
???:0
0xeeed78 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
```