https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109017
Mital Ashok <mital at mitalashok dot co.uk> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mital at mitalashok dot co.uk
--- Comment #4 from Mital Ashok <mital at mitalashok dot co.uk> ---
This is also leading to incorrect diagnostics when you forget to expand a pack.
Compare this error <https://godbolt.org/z/qP5MrdK3n>:
void f() {
[]<typename... U>(){
return sizeof(U);
}();
}
test.cpp: In lambda function:
test.cpp:4:16: error: parameter packs not expanded with '...':
[-Wtemplate-body]
4 | return sizeof(U);
| ^~~~~~~~~
test.cpp:4:16: note: 'U'
With this one <https://godbolt.org/z/jYaz4dE3s>:
template<typename>
void f() {
[]<typename... U>(){
return sizeof(U);
}();
}
test.cpp: In function 'void f()':
test.cpp:5:6: error: parameter packs not expanded with '...': [-Wtemplate-body]
3 | []<typename... U>(){
| ~~~~~~~~~~~~~~~~~~~~
4 | return sizeof(U);
| ~~~~~~~~~~~~~~~~~
5 | }();
| ~^~
test.cpp:5:6: note: 'U'
It appears that, inside another template, the unexpanded pack makes it treat
the whole lambda expression as the smallest unexpanded pattern instead of just
the part that uses the pack.
This also happens when the pack appears unexpanded in the arguments of the
lambda, not just the body <https://godbolt.org/z/PbvMhe5GE>:
template<typename>
void f() {
void([]<typename... T>(T){}...);
}
template void f<int>(); // ICE
test.cpp: In instantiation of ‘void f() [with <template-parameter-1-1> = int]’:
required from here
test.cpp:6:22:
6 | template void f<int>(); // ICE
| ^
test.cpp:3:5: internal compiler error: in tsubst_pack_expansion, at
cp/pt.cc:14082
3 | void([]<typename... T>(T){}...);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0x28c955b internal_error(char const*, ...)
../../gcc/gcc/diagnostic-global-context.cc:786
0xb03a0c fancy_abort(char const*, int, char const*)
../../gcc/gcc/diagnostics/context.cc:1803
0x87f935 tsubst_pack_expansion(tree_node*, tree_node*, int, tree_node*)