This is the mail archive of the gcc@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]

Re: suggest parentheses around assignment used as truth value


Richard Earnshaw wrote:
> 
> Of course the parentheses are necessary in that case, but the meaning is
> obvious, and the compiler can tell that a warning is unnecessary.
> 
> In my opinion, it's a bug if gcc doesn't emit a warning for
> 
>   if ((x = p())) {...}
> 
> but does for
> 
>   if (x = p()) {...}
> 
> since apart from an extra set of parentheses they are identical.  Perhaps
> the warning should be changed to "suggest explicit comparison of
> assignment used as truth value".
I think it'd be a mistake to change the behaviour of this warning and
its inhibiting syntax. It's been that way on gcc for too long. I for one
would be annoyed -- and you can tell how picky I can be about warnings
from some of my other posts :-)

It's rather hard to double the parentheses in error, and the form does
visually stand out.

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


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