Menu

#11 GCC warning about operator precedence

1.9
closed-fixed
nobody
None
5
2009-01-03
2009-01-02
No

the following file gives a warning with gcc 4.3 when using -Wall or -Wparentheses

$cat test.cc
#include <stlsoft/stlsoft.h>

void f(int foo, int bar)
{
STLSOFT_MESSAGE_ASSERT("foo bar", foo || bar);
}

$ g++ -I stlsoft-1.9.65/include/ -c test.cc -Walltest.cc: In function ‘void f(int, int)’:
test.cc:5: warning: suggest parentheses around && within ||

Whether you think the warning is useful or just annoying, it still happens.

This code (showing very bad practice by putting side effects in an assertion) causes an error:

$ cat test.cc
#include <stlsoft/stlsoft.h>

void f(int foo, int bar)
{
STLSOFT_MESSAGE_ASSERT("foo bar", foo = bar);
}
[redi@morion tmp]$ g++ -I stlsoft-1.9.65/include/ -c test.cc -Wall
test.cc: In function ‘void f(int, int)’:
test.cc:5: error: lvalue required as left operand of assignment

The attached patch is one possible fix.

Discussion

  • Jonathan Wakely

    Jonathan Wakely - 2009-01-02

    surround macro argument in parentheses

     
  • Matt Wilson

    Matt Wilson - 2009-01-03
    • status: open --> closed-fixed
     
  • Matt Wilson

    Matt Wilson - 2009-01-03

    Fixed (I think), as of 1.9.66; see https://sourceforge.net/forum/forum.php?forum_id=903896

    Thanks. :-)

     

Log in to post a comment.