For the following program:
#include<iostream>
auto f(auto ...args)
{
(std::cout << 1 << ... << args);
}
int main()
{
f(0, 0, 0);
}
gcc prints 1000
, but clang gives an error:
error: expression not permitted as operand of fold expression
(std::cout << 1 << ... << args);
~~~~~~~~~~^~~~
( )
I'm not sure I understand the error. Adding parentheses like this:
((std::cout << 1) << ... << args);
still seems to be an expression but now clang accepts this as well, and also prints 1000
.
Also, the auto
parameters for f
are irrelevant, the equivalent program written in c++17 has the same behavior (as shown in the demo).
So is the program valid?