Consider the following code snippet:
template <int... Is>
void foo()
{
([i = Is]{}(), ...);
}
clang++
(trunk) successfully compiles the code with -std=c++17
g++
(trunk) fails to compile with the following error:
<source>: In function 'void foo()':
<source>:4:11: error: parameter packs not expanded with '...':
([i = Is]{}(), ...);
^~
<source>:4:11: note: 'Is'
<source>:4:16: error: operand of fold expression has no unexpanded parameter packs
([i = Is]{}(), ...);
~~~~~~~~~~^~
on godbolt.org
Is this a g++
bug, or does the Standard prevent expansion of a parameter pack as part of a lambda-introducer?
This has the look of a bug about it.
[temp.variadic]/4
A pack expansion consists of a pattern and an ellipsis, the instantiation of which produces zero or more instantiations of the pattern in a list (described below). The form of the pattern depends on the context in which the expansion occurs. Pack expansions can occur in the following contexts:
- ... [not relevant]
- In a fold-expression; the pattern is the cast-expression that contains an unexpanded parameter pack.
A complete lambda expression (like you have) with a function call, is a valid cast-expression if one follows the grammar productions. There is no reason to preclude it from being a valid pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With