// https://godbolt.org/z/e7ebq6hYE
int print(std::string str, int i){
std::cout << i << str << std::endl;
return i;
}
template<typename ... Args>
void concat(Args ... args) {
int i = 2;
std::tuple<int, int, int, int> ret { print("ss", -22), print(args, i ) ... }; // gcc warning
std::vector<int> ret1 { print("ss", -22), print(args, i ) ... };
}
int main()
{
concat("a", "b", "c");
}
warning: operation on 'i' may be undefined [-Wsequence-point]
For the above code only gcc seem to think there is an issue with i in pack expansion, and only when the assignment is for a tuple. clang seems to compile and run without warnings.
Is it a bug in gcc or is clang not reporting this warning?
CodePudding user response:
The warning is wrong, see rule (10) here:
In list-initialization, every value computation and side effect of a given initializer clause is sequenced before every value computation and side effect associated with any initializer clause that follows it in the brace-enclosed comma-separated list of initalizers.
The rule should equally affect brace initiailization of tuples and vectors.
Note that this is not a fold expression, just a pack expansion.
