https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121575
Bug ID: 121575
Summary: ICE on structured binding to a parameter inside the
body of expansion statements
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: cooky.ykooc922 at gmail dot com
Target Milestone: ---
This testcase ICEs on the following:
struct Point {
int x, y;
};
void foo() {
Point p {1, 3};
template for (auto _ : {}) { // ok
auto [x, y] = p;
}
template for (auto _ : {0}) { // ok
auto [x, y] = p;
}
}
void bar(Point p) {
template for (auto _ : {}) { // ok
auto [x, y] = p;
}
template for (auto _ : {0}) { // ICE
auto [x, y] = p;
}
}
The ICE triggers when the structured binding binds to a destructurable
parameter inside the expansion statement that expands at least once (won't ICE
if it is the expansion is empty).
Here is the error output from godbolt:
<source>: In instantiation of 'template for' iteration 1:
required from here
<source>:20:24:
20 | template for (auto _ : {0}) {
| ^
<source>:21:23: internal compiler error: in tsubst_expr, at cp/pt.cc:22327
21 | auto [x, y] = p;
| ^
0x28a0855 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2895e76 internal_error(char const*, ...)
???:0
0xafad16 fancy_abort(char const*, int, char const*)
???:0
0xd8bbd8 finish_expansion_stmt(tree_node*, tree_node*, int, tree_node*)
???:0
0xd2db73 c_parse_file()
???:0
0xe9d0a9 c_common_parse_file()
???:0
Godbolt link: https://godbolt.org/z/zP8YecaK4