0

I cannot understand why the following code will generate unsequenced warning when compile with clang

int a=2;
a+=a-=2;

as a comparison , I can understand the following which also generate the same warning

int i=1;
i = i++ + i;

since i could be 2 or 3 (operator + is unseqnenced per C++ standard), and the warning makes sense, but for a, it seems it will always be 0 , there is no indetermination, the warning makes no sense. Please help. Many thanks!

cigien
  • 57,834
  • 11
  • 73
  • 112
yushang
  • 123
  • 2
  • 8
  • Does this answer your question? [Undefined behavior and sequence points](https://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points) See this answer in particular for your first case. It's UB before c++17, but valid from c++17. – cigien Jul 03 '20 at 16:01
  • Oops, I meant this [answer](https://stackoverflow.com/a/46171943/8372853). – cigien Jul 03 '20 at 16:21
  • 1
    thanks. I updated my clang version to 10.0 and compiled with ```/std:c++17``` which dismissed the warning. – yushang Jul 03 '20 at 16:58

0 Answers0