https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123678
Bug ID: 123678
Summary: [16 Regression] ICE (Segfault) in get_nsdmi during
instantiation of nested class within lambda in
decltype
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/3nvT7vqKe
The following c++ code crash gcc trunk.
But 12,13,14,15 with checking is fine.
Code:
```cpp
template <int = 0, class F = decltype([]<int = 1, auto G = [] {}>() {
struct MyClass {
int i = [this]() -> int {}
};
MyClass obj;
})>
void f(F op = {}) {
op();
}
int main() { f(); }
```
Stack dump:
```
<source>: In lambda function:
<source>:2:37: error: types may not be defined in 'decltype' expressions
[-Wtemplate-body]
2 | struct MyClass {
| ^
<source>:3:49: error: expected ';' at end of member declaration
[-Wtemplate-body]
3 | int i = [this]() -> int {}
| ^
| ;
<source>: In instantiation of 'constexpr<lambda()>::MyClass::MyClass()':
required from '<lambda()> [with int <anonymous> = 1; auto G = <lambda closure
object>f<>(<lambda()>)::<lambda()>()]'
<source>:5:30:
5 | MyClass obj;
| ^~~
required from 'void f(F) [with int <anonymous> = 0; F = <lambda()>]'
<source>:8:5:
8 | op();
| ~~^~
required from here
<source>:10:15:
10 | int main() { f(); }
| ~^~
<source>:5:30: error: default member initializer for '<lambda()>::MyClass::i'
required before the end of its enclosing class
5 | MyClass obj;
| ^~~
<source>:5:30: internal compiler error: Segmentation fault
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
0x2a2c57a line_maps::get_pure_location(unsigned long) const
???:0
0x2a2d83c line_maps::make_location(unsigned long, unsigned long, unsigned long)
???:0
0xc57ce0 get_nsdmi(tree_node*, bool, int)
???:0
0xc8f26d get_defaulted_eh_spec(tree_node*, int)
???:0
0xd859c0 maybe_instantiate_noexcept(tree_node*, int)
???:0
0xd8581f maybe_instantiate_noexcept(tree_node*, int)
???:0
0xc387fa mark_used(tree_node*, int)
???:0
0xb407a3 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
???:0
0xb41afd build_special_member_call(tree_node*, tree_node*, vec<tree_node*,
va_gc, vl_embed>**, tree_node*, int, int)
???:0
0xc5ee8a build_aggr_init(tree_node*, tree_node*, int, int)
???:0
0xc285d6 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
???: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
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
```