https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123647
Bug ID: 123647
Summary: [14/15/16 Regression] ICE in
cxx_eval_constant_expression with invalid struct
initialization in 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/K774c457P
The following c++ code crash gcc trunk.
And goes back to gcc 14.1 with checking.
Code:
```cpp
auto make_recursive_lambda() {
return [](auto, int a ) -> int {
struct MyStruct {
int stackList = stackList;
};
struct {
MyStruct S[2]{}
} container;
}
}
template <T> function() {
auto rec_lambda = make_recursive_lambda();
constexpr int result = rec_lambda(rec_lambda, 5);
}
```
Stack dump:
```
<source>: In lambda function:
<source>:7:21: error: expected ';' at end of member declaration
[-Wtemplate-body]
7 | MyStruct S[2]{}
| ^
| ;
<source>:9:3: warning: no return statement in function returning non-void
[-Wreturn-type]
9 | }
| ^
<source>: In function 'auto make_recursive_lambda()':
<source>:9:4: error: expected ';' before '}' token
9 | }
| ^
| ;
10 | }
| ~
<source>: At global scope:
<source>:11:11: error: 'T' has not been declared
11 | template <T> function() {
| ^
<source>:11:14: error: ISO C++ forbids declaration of 'function' with no type
[-fpermissive]
11 | template <T> function() {
| ^~~~~~~~
<source>: In function 'int function()':
in 'constexpr' expansion of
'rec_lambda.make_recursive_lambda()::<lambda(auto:1, int)>((rec_lambda,
make_recursive_lambda()::<lambda(auto:1, int)>()), 5)'
<source>:13:36:
13 | constexpr int result = rec_lambda(rec_lambda, 5);
| ~~~~~~~~~~^~~~~~~~~~~~~~~
in 'constexpr' expansion of 'container.make_recursive_lambda()::<lambda(auto:1,
int)>::<unnamed struct>::<constructor>()'
<source>:8:7:
8 | } container;
| ^~~~~~~~~
<source>:6:13: internal compiler error: unexpected expression '({...})' of kind
stmt_expr
6 | struct {
| ^
0x2950618 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x29453db internal_error(char const*, ...)
???:0
0xb8d231 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8b911 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8ea29 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb90480 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8b11f cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8b911 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8c515 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8c060 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8bd60 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8c2e4 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8c515 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8c060 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8ca35 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8bd60 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8bd60 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xb8c2e4 cxx_eval_constant_expression(constexpr_ctx const*, tree_node*,
value_cat, bool*, bool*, tree_node**)
???:0
0xe6d8df store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xc27c62 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
???: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
```