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:
> >         if ((x = p()) != 0) {...}
> > 
> > Then it becomes clear why the extra parentheses are needed.
> 
> Yes, because without the parentheses, it will be evaluated as:
> 
> 	if (x = (p() != 0)) {...}
> 
> And you're right back where you started from with a `suggest parentheses
> around assignment used as truth value' warning.
> 

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".


Richard.



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