https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123570
Bug ID: 123570
Summary: [16 Regression] ICE in
potential_constant_expression_1, at
cp/constexpr.cc:12585
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/GTza33KEc
The following invalid c++ code crash gcc trunk.
But gcc 12,13,14,15 with checking is fine.
Code:
```cpp
template <typename>
concept OuterConcept = requires() {};
struct MalformedType {
} int main() {
constexpr bool test = [] {
switch (0)
;
if ()
return OuterConcept<MalformedType>
}() || 0;
}
```
Stack dump:
```
<source>:2:36: error: expected primary-expression before '}' token
2 | concept OuterConcept = requires() {};
| ^
<source>:2:36: error: expected ';' before '}' token
2 | concept OuterConcept = requires() {};
| ^
| ;
<source>:4:2: error: expected ';' after struct definition
4 | } int main() {
| ^
| ;
<source>: In lambda function:
<source>:8:9: error: expected primary-expression before ')' token
8 | if ()
| ^
<source>:9:41: error: expected ';' before '}' token
9 | return OuterConcept<MalformedType>
| ^
| ;
10 | }() || 0;
| ~
<source>: In function 'int main()':
<source>:10:4: error: 'main()::<lambda()>' called in a constant expression
5 | constexpr bool test = [] {
| ~~~~
6 | switch (0)
| ~~~~~~~~~~
7 | ;
| ~
8 | if ()
| ~~~~~
9 | return OuterConcept<MalformedType>
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 | }() || 0;
| ~^~
<source>:5:25: note: 'main()::<lambda()>' is not usable as a 'constexpr'
function because:
5 | constexpr bool test = [] {
| ^
<source>:6:5: sorry, unimplemented: unexpected AST of kind switch_expr
6 | switch (0)
| ^~~~~~
<source>:6:5: internal compiler error: in potential_constant_expression_1, at
cp/constexpr.cc:12585
0x2924328 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x29190eb internal_error(char const*, ...)
???:0
0xb1632c fancy_abort(char const*, int, char const*)
???:0
0xb99875 require_potential_rvalue_constant_expression(tree_node*)
???:0
0xb99a55 explain_invalid_constexpr_fn(tree_node*)
???:0
0xe479be store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xc1dcfe cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
???:0
0xd56dd3 c_parse_file()
???:0
0xec8829 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
```