[cfe-dev] Why is if ((x == 1)) a warning?

Andrew Fish afish at apple.com
Thu Jun 2 16:01:51 PDT 2011


The gcc definition of -Wparentheses does not seem to include the extraneous parentheses case. I also noticed that older versions of clang don't flag this kind of warning.

I could turn off -Wparentheses, but the other checking it does is quite useful. 

I could change the code, but the maintainers of the open source site don't think that this is valid warning. Does anyone know the history or reason behind this warning?  


Andrew Fish

./clang -S -Wall ~/work/Compiler/w.c 
/Users/fish/work/Compiler/w.c:5:9: warning: equality comparison with extraneous parentheses [-Wparentheses]
 if ((x == 1)) {
      ~~^~~~
/Users/fish/work/Compiler/w.c:5:9: note: remove extraneous parentheses around the comparison to silence this warning
 if ((x == 1)) {
     ~  ^   ~
/Users/fish/work/Compiler/w.c:5:9: note: use '=' to turn this equality comparison into an assignment
 if ((x == 1)) {
        ^~
        =
1 warning generated.
~/work/Loki/ToolChain/clang/bin>gcc  -S -Wall 

cat  ~/work/Compiler/w.c 

int
test (int x)
{
 if ((x == 1)) {
   return 0;
 }

 return 1;
}






More information about the cfe-dev mailing list