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/46742] New: -Wparentheses unexpectedly misses some cases


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

           Summary: -Wparentheses unexpectedly misses some cases
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mikpe@it.uu.se


> cat bug.c
int foo(unsigned int mask) { return (!mask & 2) ? 1 : 0; }
int bar(unsigned int mask) { return (!mask & 1) ? 1 : 0; }
> gcc -Wparentheses -S bug.c
bug.c: In function 'foo':
bug.c:1:1: warning: suggest parentheses around operand of '!' or change '&' to
'&&' or '!' to '~'

gcc warns about foo(), which is good, but why doesn't it warn about bar()?  For
some reason the number of the bit being inspected affects the compiler's
ability to detect the typo and issue the warning.

> gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/mikpe/pkgs/linux-x86_64/gcc-4.5.1/libexec/gcc/x86_64-unknown-linux-gnu/4.5.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /tmp/gcc-4.5.1/configure
--prefix=/home/mikpe/pkgs/linux-x86_64/gcc-4.5.1
--with-gmp=/home/mikpe/pkgs/linux-x86_64/gmp-4.3.2
--with-mpfr=/home/mikpe/pkgs/linux-x86_64/mpfr-2.4.2
--with-mpc=/home/mikpe/pkgs/linux-x86_64/mpc-0.8.2 --disable-plugin
--disable-lto --disable-nls --disable-shared --disable-libmudflap
--enable-multilib --enable-threads=posix --enable-checking=release
--enable-languages=c,ada

Side note, shouldn't there be a "diagnostic" component in bugzilla?  For now I
chose "C frontend", which may or may not be appropriate.


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