[cfe-dev] Why is if ((x == 1)) a warning?
Cory Nelson
phrosty at gmail.com
Thu Jun 2 16:30:56 PDT 2011
On Thu, Jun 2, 2011 at 4:01 PM, Andrew Fish <afish at apple.com> wrote:
> 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?
>
You get a warning for if(x = 1). to clarify that you actually want =
instead of == and to disable the warning, you use if((x = 1)). I
guess the warning you're seeing is the reverse of that, making sure
you didn't actually want if((x = 1)).
--
Cory Nelson
http://int64.org
More information about the cfe-dev
mailing list