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 tfn1(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 tfn2(T t
, U u
) { return ((!t
) == u
); }
17 template <class T
, class U
> bool tfn3(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 tfn4(T t
, U u
) { return ((!g(t
)) == u
); }
19 template <class T
, class U
> bool tfn5(T t
, U u
) { return (!!t
== u
); } /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
20 template <class T
, class U
> bool tfn6(T t
, U u
) { return (!!g(t
) == u
); } /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
21 template <int N
> bool tfn7(int i1
, int i2
) { return (!i1
== i2
); } /* { dg-warning "logical not is only applied to the left hand side of comparison" "" { target c++ } 21 } */
25 fn1 (int i1
, int i2
, bool b1
, bool b2
)
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" } */
30 b
= !i1
> i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
31 b
= !i1
<= i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
32 b
= !i1
>= i2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
41 /* Parens suppress the warning. */
49 /* ...but not these parens. */
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" } */
53 b
= (!i1
> i2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
54 b
= (!i1
<= i2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
55 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" } */
72 b
= (!foo_i ()) == i1
;
75 b
= !!i1
== i2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
76 b
= !!i1
!= i2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
77 b
= !!i1
< i2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
78 b
= !!i1
> i2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
79 b
= !!i1
<= i2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
80 b
= !!i1
>= i2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
81 b
= !!foo_i () == i1
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
90 /* Be careful here. */
96 b
= !5 == 4; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
97 b
= !!5 == 4; /* { dg-bogus "logical not is only applied to the left hand side of comparison" "" { xfail *-*-* } } */
98 b
= !1 == 1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
99 b
= !!1 == 1; /* { dg-bogus "logical not is only applied to the left hand side of comparison" "" { xfail *-*-* } } */
108 b
= foo_e () == foo_e ();
111 b
= !e
== foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
113 b
= !foo_e () == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
116 b
= !(e
== foo_e ());
117 b
= !(foo_e () == A
);
118 b
= !(foo_e () == foo_e ());
121 b
= (!e
) == foo_e ();
122 b
= (!foo_e ()) == A
;
123 b
= (!foo_e ()) == foo_e ();
127 fn3 (int i1
, float f2
)
129 b
= !i1
== f2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
130 b
= !i1
!= f2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
131 b
= !i1
< f2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
132 b
= !i1
> f2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
133 b
= !i1
<= f2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
134 b
= !i1
>= f2
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
143 /* Parens suppress the warning. */
151 /* ...but not these parens. */
152 b
= (!i1
== f2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
153 b
= (!i1
!= f2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
154 b
= (!i1
< f2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
155 b
= (!i1
> f2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
156 b
= (!i1
<= f2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
157 b
= (!i1
>= f2
); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
159 b
= !!i1
== f2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
160 b
= !!i1
!= f2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
161 b
= !!i1
< f2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
162 b
= !!i1
> f2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
163 b
= !!i1
<= f2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
164 b
= !!i1
>= f2
; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
173 b
= foo_e () == foo_e ();
175 b
= !e
== B
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
176 b
= !e
== foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
177 b
= !foo_e () == B
; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
178 b
= !foo_e () == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
181 b
= !(e
== foo_e ());
182 b
= !(foo_e () == B
);
183 b
= !(foo_e () == foo_e ());
186 b
= (!e
) == foo_e ();
187 b
= (!foo_e ()) == B
;
188 b
= (!foo_e ()) == foo_e ();