public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/46509] New: -Wparentheses shouldn't warn about: A || Y && "foo"
@ 2010-11-16 22:18 sabre at nondot dot org
  2010-11-16 22:22 ` [Bug c/46509] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sabre at nondot dot org @ 2010-11-16 22:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46509

           Summary: -Wparentheses shouldn't warn about: A || Y && "foo"
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sabre@nondot.org


Per the subject, -Wparentheses shouldn't warn about possible ||/&& precedence
issues if the operand to the or is always false or the operand to && is always
true.  These should not warn:

if (a || b && 1) 
if (0 || a && b) 

They shouldn't warn because even if the user is confused about precedence, the
order of evaluation doesn't affect the result of the computation.

This happens to come up frequently for coding standards that use messages in
asserts, e.g.:

assert(A == 1 || A == 3 && "some reason this property should hold"); 

-Chris


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/46509] -Wparentheses shouldn't warn about: A || Y && "foo"
  2010-11-16 22:18 [Bug c/46509] New: -Wparentheses shouldn't warn about: A || Y && "foo" sabre at nondot dot org
@ 2010-11-16 22:22 ` pinskia at gcc dot gnu.org
  2010-11-17 11:53 ` rguenth at gcc dot gnu.org
  2010-11-17 12:16 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-11-16 22:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46509

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-11-16 22:17:45 UTC ---
>A == 1 || A == 3 && "some reason this property should hold"

To the untrained eye this looks funny really.  The parentheses makes the code
look cleaner and better understood as far as I can tell.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/46509] -Wparentheses shouldn't warn about: A || Y && "foo"
  2010-11-16 22:18 [Bug c/46509] New: -Wparentheses shouldn't warn about: A || Y && "foo" sabre at nondot dot org
  2010-11-16 22:22 ` [Bug c/46509] " pinskia at gcc dot gnu.org
@ 2010-11-17 11:53 ` rguenth at gcc dot gnu.org
  2010-11-17 12:16 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-11-17 11:53 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46509

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/46509] -Wparentheses shouldn't warn about: A || Y && "foo"
  2010-11-16 22:18 [Bug c/46509] New: -Wparentheses shouldn't warn about: A || Y && "foo" sabre at nondot dot org
  2010-11-16 22:22 ` [Bug c/46509] " pinskia at gcc dot gnu.org
  2010-11-17 11:53 ` rguenth at gcc dot gnu.org
@ 2010-11-17 12:16 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-17 12:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46509

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-17 12:07:43 UTC ---
Agreed, this is a terrible coding standard, I don't think we should try to
special case it.  It is much better if ()s are added.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-11-17 12:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-16 22:18 [Bug c/46509] New: -Wparentheses shouldn't warn about: A || Y && "foo" sabre at nondot dot org
2010-11-16 22:22 ` [Bug c/46509] " pinskia at gcc dot gnu.org
2010-11-17 11:53 ` rguenth at gcc dot gnu.org
2010-11-17 12:16 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).