https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123687
Bug ID: 123687
Summary: [16 Regression] ICE in instantiate_decl (at cp/pt.cc)
during constant evaluation of invalid static member in
lambda-NTTP local class
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/fcGj4MxTs
The following c++ code crash gcc trunk.
But 15.2 with checking is fine.
Code:
```cpp
template<auto = []{
struct S {
static constexpr int n = -1;
};
S::n;
}>
void f() {
}
```
Stack dump:
```
<source>: In lambda function:
<source>:3:30: error: local class 'struct<lambda()>::S' shall not have static
data member 'constexpr const int <lambda()>::S::n' [-Wtemplate-body]
3 | static constexpr int n = -1;
| ^
<source>: In instantiation of 'constexpr const int <lambda()>::S::n':
required from here
<source>:5:8:
5 | S::n;
| ^
<source>:5:8: internal compiler error: in instantiate_decl, at cp/pt.cc:28515
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
0xb1ec72 fancy_abort(char const*, int, char const*)
???:0
0xc36863 maybe_instantiate_decl(tree_node*)
???:0
0xc368af decl_constant_var_p(tree_node*)
???:0
0xe153b4 finish_id_expression(tree_node*, tree_node*, tree_node*, cp_id_kind*,
bool, bool, bool*, bool, bool, bool, bool, char const**, unsigned long)
???:0
0xd64c43 c_parse_file()
???:0
0xeeed69 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
```