public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17896] The expression (a>0 & b>0) should give clearer warning message (-Wparentheses)
       [not found] <bug-17896-4@http.gcc.gnu.org/bugzilla/>
@ 2012-04-26 22:24 ` manu at gcc dot gnu.org
  2021-09-28 10:20 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2012-04-26 22:24 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

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

--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-26 22:23:59 UTC ---
manuel@gcc12:~$ clang -Wextra -Wall -Weverything -fsyntax-only pr17896.c
pr17896.c:4:1: warning: no previous prototype for function 'bar'
[-Wmissing-prototypes]
bar (int a, int b, int c)
^
pr17896.c:7:17: warning: & has lower precedence than ==; == will be evaluated
first [-Wparentheses]
    foo (a == b & (b == c));   /* { dg-warning "boolean" "correct warning" } */
         ~~~~~~~^
pr17896.c:7:17: note: place parentheses around the == expression to silence
this warning
    foo (a == b & (b == c));   /* { dg-warning "boolean" "correct warning" } */
                ^
                  (       )
pr17896.c:7:17: note: place parentheses around the & expression to evaluate it
first
    foo (a == b & (b == c));   /* { dg-warning "boolean" "correct warning" } */
                ^
              (           )
pr17896.c:8:19: warning: & has lower precedence than ==; == will be evaluated
first [-Wparentheses]
    foo ((a == b) & b == c);   /* { dg-warning "boolean" "correct warning" } */
                  ^~~~~~~~
pr17896.c:8:19: note: place parentheses around the == expression to silence
this warning
    foo ((a == b) & b == c);   /* { dg-warning "boolean" "correct warning" } */
                  ^
                    (     )
pr17896.c:8:19: note: place parentheses around the & expression to evaluate it
first
    foo ((a == b) & b == c);   /* { dg-warning "boolean" "correct warning" } */
                  ^
         (           )
pr17896.c:13:16: warning: | has lower precedence than ==; == will be evaluated
first [-Wparentheses]
   foo (a == b | (b == c));   /* { dg-warning "boolean" "correct warning" } */
        ~~~~~~~^
pr17896.c:13:16: note: place parentheses around the == expression to silence
this warning
   foo (a == b | (b == c));   /* { dg-warning "boolean" "correct warning" } */
               ^
                 (       )
pr17896.c:13:16: note: place parentheses around the | expression to evaluate it
first
   foo (a == b | (b == c));   /* { dg-warning "boolean" "correct warning" } */
               ^
             (           )
pr17896.c:14:18: warning: | has lower precedence than ==; == will be evaluated
first [-Wparentheses]
   foo ((a == b) | b == c);   /* { dg-warning "boolean" "correct warning" } */
                 ^~~~~~~~
pr17896.c:14:18: note: place parentheses around the == expression to silence
this warning
   foo ((a == b) | b == c);   /* { dg-warning "boolean" "correct warning" } */
                 ^
                   (     )
pr17896.c:14:18: note: place parentheses around the | expression to evaluate it
first
   foo ((a == b) | b == c);   /* { dg-warning "boolean" "correct warning" } */
                 ^
        (           )
5 warnings generated.


manuel@gcc12:~$ ~/trunk/186353/build/gcc/cc1 -Wextra -Wall -Wlogical-op
-fsyntax-only pr17896.c 
 bar
pr17896.c: In function ‘bar’:
pr17896.c:6:5: warning: suggest parentheses around comparison in operand of ‘&’
[-Wparentheses]
     foo (a == b & b == c);     /* { dg-warning "boolean" "correct warning" }
*/
     ^
pr17896.c:7:5: warning: suggest parentheses around comparison in operand of ‘&’
[-Wparentheses]
     foo (a == b & (b == c));   /* { dg-warning "boolean" "correct warning" }
*/
     ^
pr17896.c:8:5: warning: suggest parentheses around comparison in operand of ‘&’
[-Wparentheses]
     foo ((a == b) & b == c);   /* { dg-warning "boolean" "correct warning" }
*/
     ^
pr17896.c:9:5: warning: suggest parentheses around comparison in operand of ‘&’
[-Wparentheses]
     foo (++a == b & b == c);   /* { dg-warning "comparison" "correct warning"
} */
     ^
pr17896.c:12:5: warning: suggest parentheses around comparison in operand of
‘|’ [-Wparentheses]
     foo (a == b | b == c);     /* { dg-warning "boolean" "correct warning" }
*/
     ^
pr17896.c:13:4: warning: suggest parentheses around comparison in operand of
‘|’ [-Wparentheses]
    foo (a == b | (b == c));   /* { dg-warning "boolean" "correct warning" } */
    ^
pr17896.c:14:4: warning: suggest parentheses around comparison in operand of
‘|’ [-Wparentheses]
    foo ((a == b) | b == c);   /* { dg-warning "boolean" "correct warning" } */
    ^
pr17896.c:15:4: warning: suggest parentheses around comparison in operand of
‘|’ [-Wparentheses]
    foo (++a == b | b == c);   /* { dg-warning "comparison" "correct warning" }
*/
    ^


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

* [Bug c/17896] The expression (a>0 & b>0) should give clearer warning message (-Wparentheses)
       [not found] <bug-17896-4@http.gcc.gnu.org/bugzilla/>
  2012-04-26 22:24 ` [Bug c/17896] The expression (a>0 & b>0) should give clearer warning message (-Wparentheses) manu at gcc dot gnu.org
@ 2021-09-28 10:20 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-28 10:20 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The patch no longer applies as the code has moved to c-family/c-warn.c in the
function warn_about_parentheses.

I do think we should be able to do a fixit type though.

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

* [Bug c/17896] The expression (a>0 & b>0) should give clearer warning message (-Wparentheses)
  2004-10-08 19:55 [Bug c/17896] New: " trt at acm dot org
                   ` (2 preceding siblings ...)
  2004-10-09 21:24 ` trt at acm dot org
@ 2004-10-11 17:12 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-11 17:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-11 17:12 -------
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-10/msg00918.html>.
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic, patch
   Last reconfirmed|0000-00-00 00:00:00         |2004-10-11 17:12:24
               date|                            |


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


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

* [Bug c/17896] The expression (a>0 & b>0) should give clearer warning message (-Wparentheses)
  2004-10-08 19:55 [Bug c/17896] New: " trt at acm dot org
  2004-10-08 20:00 ` [Bug c/17896] " trt at acm dot org
  2004-10-08 20:11 ` pinskia at gcc dot gnu dot org
@ 2004-10-09 21:24 ` trt at acm dot org
  2004-10-11 17:12 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: trt at acm dot org @ 2004-10-09 21:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2004-10-09 21:24 -------
Sorry, will do.  Should bugzilla do this automatically for 'patch' attachments?

-- 


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


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

* [Bug c/17896] The expression (a>0 & b>0) should give clearer warning message (-Wparentheses)
  2004-10-08 19:55 [Bug c/17896] New: " trt at acm dot org
  2004-10-08 20:00 ` [Bug c/17896] " trt at acm dot org
@ 2004-10-08 20:11 ` pinskia at gcc dot gnu dot org
  2004-10-09 21:24 ` trt at acm dot org
  2004-10-11 17:12 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-08 20:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-10-08 20:11 -------
As I have mentioned before patches goto gcc-patches@gcc.gnu.org.

-- 


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


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

* [Bug c/17896] The expression (a>0 & b>0) should give clearer warning message (-Wparentheses)
  2004-10-08 19:55 [Bug c/17896] New: " trt at acm dot org
@ 2004-10-08 20:00 ` trt at acm dot org
  2004-10-08 20:11 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: trt at acm dot org @ 2004-10-08 20:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From trt at acm dot org  2004-10-08 20:00 -------
Created an attachment (id=7310)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7310&action=view)
proposed patch

I've attached a proposed patch for gcc to issue alternate warnings:
 
    suggest && instead of & when joining booleans
    suggest || instead of | when joining booleans
 
The patched gcc continues to warn (or not) as before, but with different text
when the operands are boolean-valued and without side effects.
I used COMPARISON_CLASS_P (t) as an approximation to "boolean-valued".
truth_value_p (TREE_CODE (t)) would be better but is unavailable.


-- 


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


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

end of thread, other threads:[~2021-09-28 10:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-17896-4@http.gcc.gnu.org/bugzilla/>
2012-04-26 22:24 ` [Bug c/17896] The expression (a>0 & b>0) should give clearer warning message (-Wparentheses) manu at gcc dot gnu.org
2021-09-28 10:20 ` pinskia at gcc dot gnu.org
2004-10-08 19:55 [Bug c/17896] New: " trt at acm dot org
2004-10-08 20:00 ` [Bug c/17896] " trt at acm dot org
2004-10-08 20:11 ` pinskia at gcc dot gnu dot org
2004-10-09 21:24 ` trt at acm dot org
2004-10-11 17:12 ` pinskia at gcc dot gnu dot 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).