, Clang:
$ clang++ -Weverything test.cpp
test.cpp:4:5: warning: no previous prototype for function 'foo' [-Wmissing-prototypes]
int foo()
^
test.cpp:6:10: warning: expression result unused [-Wunused-value]
return 1,2,3,4,5,6;
^
test.cpp:6:12: warning: expression result unused [-Wunused-value]
return 1,2,3,4,5,6;
^
test.cpp:6:14: warning: expression result unused [-Wunused-value]
return 1,2,3,4,5,6;
^
test.cpp:6:16: warning: expression result unused [-Wunused-value]
return 1,2,3,4,5,6;
^
test.cpp:6:18: warning: expression result unused [-Wunused-value]
return 1,2,3,4,5,6;
^
6 warnings generated.
, -Weverything . , , .
For explanations: see The Mystical Answer for a comma and its sequencing effects. One of the useful cases of this operator is:
std::list<Item> list = ;
assert(list.size() >= 10);
auto it = list.begin();
for (int i = 0; i < 10; ++i, ++it) {
std::cout << "Item " << i << ": " << *it << "\n";
}
Note that the third section of the loop foruses the comma operator to perform two operations in the same expression.
Of course, this syntax is mostly anecdotal, so people are regularly surprised ...
source
share