This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/77434] warn about suspicious precedence of ternary operator (?:)
- From: "glisse at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 31 Aug 2016 21:31:52 +0000
- Subject: [Bug c++/77434] warn about suspicious precedence of ternary operator (?:)
- Auto-submitted: auto-generated
- References: <bug-77434-4@http.gcc.gnu.org/bugzilla/>
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).