The warning is obvious, but I'm using a real compiler:
void foo() { bool bSwitch = true; double dSum = 1 + bSwitch?1:2; }
gives:
$ clang++ -fsyntax-only test.cpp test.cpp:3:28: warning: operator '?:' has lower precedence than '+'; '+' will be evaluated first [-Wparentheses] double dSum = 1 + bSwitch?1:2; ~~~~~~~~~~~^ test.cpp:3:28: note: place parentheses around the '+' expression to silence this warning double dSum = 1 + bSwitch?1:2; ^ ( ) test.cpp:3:28: note: place parentheses around the '?:' expression to evaluate it first double dSum = 1 + bSwitch?1:2; ^ ( ) 1 warning generated.
And yes, I gave it all over the command line, by default.
source share