http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51545

             Bug #: 51545
           Summary: missing -Wparentheses diagnostic  with compound
                    assignment used as condition
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: m...@gcc.gnu.org


Noticed here:
http://llvm.org/devmtg/2011-11/Weber_Wennborg_UsingClangInChromium.pdf

Testcase:

int foo(int x, int y)
{
  if (x|=y) return 0;
  return 1;
}

gcc 4.7 -Wall -Wextra -Wparentheses -Wlogical-op -Wtype-limits prints nothing.

clang 3.0 without extra flags:

test.cc:3:8: warning: using the result of an assignment as a condition without
parentheses [-Wparentheses]
  if (x|=y) return 0;
      ~^~~
test.cc:3:8: note: place parentheses around the assignment to silence this
warning                           
  if (x|=y) return 0;
       ^
      (   )
test.cc:3:8: note: use '!=' to turn this compound assignment into an inequality
comparison
  if (x|=y) return 0;
       ^~
       !=
1 warning generated.


Nonetheless, I still believe that using extra parentheses to silence these
warnings actually hides bugs and there are better alternatives. See PR25733.

Reply via email to