This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/51545] New: missing -Wparentheses diagnostic with compound assignment used as condition


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: unassigned@gcc.gnu.org
        ReportedBy: manu@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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]