As I may know that shift operator <<
doesn't guarantee the order of evaluation of it its operands so an expression like this:
int i = 0;
cout << i << i++ << endl; // UB
But I think the new standard C++17 adds the shift operator to sequenced operators which guarantees to evaluates its lhs
operand then its rhs
.
So the expression above if compiled using C++17 or C++20 it will be ok:
int i = 0;
cout << i << i++ << endl; // 00
- But when I compile it using GCC and CLang passing
-std=c++17
and-std=c++2a
I get the same warningoperation on 'i' maybe undefined [-Wsequence-point]
.
So Is it safe to do so or it is UB that I should never do? Thank you.