2 /* { dg-do compile } */
3 /* { dg-options "-Wlogical-not-parentheses" } */
10 extern enum E
foo_e (void);
11 extern bool foo_b (void);
12 extern int foo_i (void);
15 template <class T
, class U
> bool f1(T t
, U u
) { return (!t
== u
); } /* { dg-warning "logical not is only applied to the left hand side of comparison" "" { target c++ } 15 } */
16 template <class T
, class U
> bool f2(T t
, U u
) { return ((!t
) == u
); }
17 template <class T
, class U
> bool f3(T t
, U u
) { return (!g(t
) == u
); } /* { dg-warning "logical not is only applied to the left hand side of comparison" "" { target c++ } 17 } */
18 template <class T
, class U
> bool f4(T t
, U u
) { return ((!g(t
)) == u
); }
22 fn1 (int i1
, int i2
, bool b1
, bool b2
)
24 b
= !i1
== i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
25 b
= !i1
!= i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
26 b
= !i1
< i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
27 b
= !i1
> i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
28 b
= !i1
<= i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
29 b
= !i1
>= i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
38 /* Parens suppress the warning. */
46 /* ...but not these parens. */
47 b
= (!i1
== i2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
48 b
= (!i1
!= i2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
49 b
= (!i1
< i2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
50 b
= (!i1
> i2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
51 b
= (!i1
<= i2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
52 b
= (!i1
>= i2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
61 b
= !foo_i () == i1
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
62 b
= (!foo_i ()) == i1
;
65 b
= !!i1
== i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
66 b
= !!i1
!= i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
67 b
= !!i1
< i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
68 b
= !!i1
> i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
69 b
= !!i1
<= i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
70 b
= !!i1
>= i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
71 b
= !!foo_i () == i1
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
73 /* Be careful here. */
86 b
= foo_e () == foo_e ();
88 b
= !e
== A
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
89 b
= !e
== foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
90 b
= !foo_e () == A
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
91 b
= !foo_e () == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
96 b
= !(foo_e () == foo_e ());
100 b
= (!foo_e ()) == A
;
101 b
= (!foo_e ()) == foo_e ();