https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124196
Bug ID: 124196
Summary: ICE in template-for using tuples and variadic
templates
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: uchanahome8 at gmail dot com
Target Milestone: ---
Hi, I am using the gcc-trunk on compiler explorer:
https://godbolt.org/z/vePfcjE4j and was able to reproduce this on local build
of master branch as well.
Code:
```
#include <iostream>
#include <utility>
#include <array>
template <std::size_t N>
consteval auto make_array() {
std::array<std::size_t, N> arr;
for (int i = 0; i < N; ++i)
arr[i] = i;
return arr;
}
template <typename... T>
struct X {
std::tuple<T...> tuple;
static constexpr auto size = sizeof...(T);
X(T... v) : tuple{v...} {
template for (constexpr int I : make_array<size>()) {
const auto& v = std::get<I>(tuple);
}
}
};
int main() {
X<int, int, int> x(1,2,3);
return 0;
}
```
If I remove `const auto& v = std::get<I>(tuple);`, or replace
`make_array<size>()` with `{0,1,2}`, the code compiles.
Error:
```
<source>: In constructor 'X<T>::X(T ...) [with T = {int, int, int}]':
<source>:19:37: internal compiler error: in gimple_add_tmp_var, at
gimplify.cc:841
19 | template for (constexpr int I : make_array<size>()) {
| ^
0x2961fa8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2956ceb internal_error(char const*, ...)
???:0
0xb215b0 fancy_abort(char const*, int, char const*)
???:0
0x11f5091 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f4507 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f3e5b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f4330 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f3e5b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f4330 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f4330 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f3e5b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f4330 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x1218556 gimplify_body(tree_node*, bool)
???:0
/cefs/b2/b2e22475d9f80609b94e5b26_gcc-trunk-20260221/bin/../libexec/gcc/x86_64-linux-gnu/16.0.1/cc1plus
-fpreprocessed /app/output.ii -quiet -dumpdir /app/ -dumpbase output.cpp
-dumpbase-ext .cpp -masm=intel -mtune=generic -march=x86-64 -g -Werror
-std=c++26 -fdiagnostics-color=always -fno-verbose-asm -freport-bug -o
/app/output.s
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Preprocessed source stored into /tmp/ccpckidD.out file, please attach this to
your bugreport.
ASM generation compiler returned: 1
<source>: In constructor 'X<T>::X(T ...) [with T = {int, int, int}]':
<source>:19:37: internal compiler error: in gimple_add_tmp_var, at
gimplify.cc:841
19 | template for (constexpr int I : make_array<size>()) {
| ^
0x2961fa8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2956ceb internal_error(char const*, ...)
???:0
0xb215b0 fancy_abort(char const*, int, char const*)
???:0
0x11f5091 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f4507 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f3e5b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f4330 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f3e5b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f4330 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f4330 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f3e5b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x11f70aa gimplify_stmt(tree_node**, gimple**)
???:0
0x11f4330 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0x1218556 gimplify_body(tree_node*, bool)
???:0
/cefs/b2/b2e22475d9f80609b94e5b26_gcc-trunk-20260221/bin/../libexec/gcc/x86_64-linux-gnu/16.0.1/cc1plus
-fpreprocessed /app/output.s-example.ii -quiet -dumpdir /app/output.s-
-dumpbase example.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -g
-Werror -std=c++26 -fdiagnostics-color=always -fno-verbose-asm -freport-bug -o
/app/output.s-example.s
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Preprocessed source stored into /tmp/ccHpHwb0.out file, please attach this to
your bugreport.
Execution build compiler returned: 1
Build failed
```