[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c++/77434] warn about suspicious precedence of ternary operator (?:)
From:       "glisse at gcc dot gnu.org" <gcc-bugzilla () gcc ! gnu ! org>
Date:       2016-08-31 21:31:52
Message-ID: bug-77434-4-FXhJ4qUuqs () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77434

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to joseph@codesourcery.com from comment #2)
> following is not suspicious and it would seem silly to warn for it:
> 
> return (a > 0 && b <= 3 ? 1 : 2);
> 
> (because the suggested alternative parse would involve b <= 3 ? 1 : 2 as 
> RHS of &&, which is unnatural as a conditional expression in boolean 
> context where the halves of the expression aren't boolean).

While there is only one sensible parsing, in a code review I would still ask
for parentheses, so that the reader can more quickly find that one sensible
parsing and be certain that the compiler agrees. But it becomes a matter of
style, and people complain every time we add a style warning, so maybe your
restricted warning would be best (easier to include in -Wall).=
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic