https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123564
Bug ID: 123564
Summary: [13/14/15/16 Regression] ICE in
break_out_target_exprs, at cp/tree.cc:3438 with
-std=c++23 flag
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/oxPKE73fc
The following c++ code crash gcc trunk with -std=c++23 flag.
And goes back to 13.1 with checking.
Code:
```cpp
struct Container {
Container();
};
struct S {
constexpr S() { Container c; }
constexpr operator[](int x) { return 0; }
template <T> void foo() { static_assert(S()[0]); }
};
```
Stack dump:
```
<source>:6:13: error: ISO C++ forbids declaration of 'operator[]' with no type
[-fpermissive]
6 | constexpr operator[](int x) { return 0; }
| ^~~~~~~~
<source>:7:13: error: 'T' has not been declared
7 | template <T> void foo() { static_assert(S()[0]); }
| ^
<source>: In member function 'void S::foo()':
<source>:7:29: error: non-constant condition for static assertion
[-Wtemplate-body]
7 | template <T> void foo() { static_assert(S()[0]); }
| ^~~~~~~~~~~~~
<source>:7:43: error: 'constexpr S::S()' called in a constant expression
[-Wtemplate-body]
7 | template <T> void foo() { static_assert(S()[0]); }
| ^~~
<source>:5:13: note: 'constexpr S::S()' is not usable as a 'constexpr' function
because:
5 | constexpr S() { Container c; }
| ^
<source>:5:13: internal compiler error: in break_out_target_exprs, at
cp/tree.cc:3438
0x2926688 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x291b44b internal_error(char const*, ...)
???:0
0xb16d54 fancy_abort(char const*, int, char const*)
???:0
0xb9a41a explain_invalid_constexpr_fn(tree_node*)
???:0
0xb94d63 cxx_constant_value(tree_node*, tree_node*, int)
???:0
0xde751a finish_static_assert(tree_node*, tree_node*, unsigned long, bool,
bool, bool)
???:0
0xd57563 c_parse_file()
???:0
0xec8ee9 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
```