https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123535
Bug ID: 123535
Summary: [16 Regression] ICE in tsubst_expr, at cp/pt.cc:22369
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/n7Ysa7rTM
The following c++ code crash gcc trunk. But gcc 13,14,15 is fine.
Code:
```cpp
void (*p)(int) = [](auto) {
for (int i = 0;;) {
auto loop_lambda = [&](auto&& self, int j) -> void {
struct NestedTemplate {
static constexpr int value = i;
};
};
loop_lambda(loop_lambda, 0);
}
};
```
Stack dump:
```
<source>: In lambda function:
<source>:5:38: error: local class 'struct<lambda(auto:1)>::<lambda(auto:2&&,
int)>::NestedTemplate' shall not have static data member 'constexpr const int
<lambda(auto:1)>::<lambda(auto:2&&, int)>::NestedTemplate::value'
[-Wtemplate-body]
5 | static constexpr int value = i;
| ^~~~~
<source>: In instantiation of 'constexpr const int
<lambda(auto:1)>::<lambda(auto:2&&, int)>::NestedTemplate::value':
required from '<lambda(auto:1)>::<lambda(auto:2&&, int)> [with auto:2 =
<lambda(auto:1)>::<lambda(auto:2&&, int)>&]'
<source>:6:13:
6 | };
| ^
required from '<lambda(auto:1)> [with auto:1 = int]'
<source>:8:20:
8 | loop_lambda(loop_lambda, 0);
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~
required by substitution of 'template<class auto:1>
constexpr<lambda(auto:1)>::operator decltype
(((const<lambda(auto:1)>*)0)->operator()<auto:1>(static_cast<auto:1&&>(<anonymous>)))
(*)(auto:1)() const [with auto:1 = int]'
<source>:1:18:
1 | void (*p)(int) = [](auto) {
| ^
required from here
<source>:10:1:
10 | };
| ^
<source>:5:46: internal compiler error: in tsubst_expr, at cp/pt.cc:22369
5 | static constexpr int value = i;
| ^
0x2924d48 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2919b0b internal_error(char const*, ...)
???:0
0xb16bf2 fancy_abort(char const*, int, char const*)
???:0
0xdb94ad instantiate_decl(tree_node*, bool, bool)
???:0
0xdb94ad instantiate_decl(tree_node*, bool, bool)
???:0
0xdc2eba instantiate_pending_templates(int)
???:0
0xc328b8 c_parse_final_cleanups()
???:0
0xec8e18 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
```