This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug c++/77434] warn about suspicious precedence of ternary operator (?:)


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

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