2 /* { dg-do compile } */
3 /* { dg-options "-Wlogical-op" } */
11 #if __SIZEOF_INT__ < 4
12 __extension__
typedef __INT32_TYPE__
int32_t;
13 __extension__
typedef __UINT32_TYPE__
uint32_t;
14 __extension__
typedef __INT16_TYPE__
int16_t;
17 typedef unsigned int uint32_t;
18 typedef short int16_t;
21 extern int32_t bar (void);
23 struct R
{ int32_t a
, b
; } S
;
26 andfn (int32_t a
, int32_t b
)
28 if (a
&& a
) {} /* { dg-warning "logical .and. of equal expressions" } */
29 if (!a
&& !a
) {} /* { dg-warning "logical .and. of equal expressions" } */
30 if (!!a
&& !!a
) {} /* { dg-warning "logical .and. of equal expressions" } */
31 if (a
> 0 && a
> 0) {} /* { dg-warning "logical .and. of equal expressions" } */
32 if (a
< 0 && a
< 0) {} /* { dg-warning "logical .and. of equal expressions" } */
33 if (a
== 0 && a
== 0) {} /* { dg-warning "logical .and. of equal expressions" } */
34 if (a
<= 0 && a
<= 0) {} /* { dg-warning "logical .and. of equal expressions" } */
35 if (a
>= 0 && a
>= 0) {} /* { dg-warning "logical .and. of equal expressions" } */
36 if (a
== 0 && !(a
!= 0)) {} /* { dg-warning "logical .and. of equal expressions" } */
38 if (a
&& a
&& a
) {} /* { dg-warning "logical .and. of equal expressions" } */
39 if ((a
+ 1) && (a
+ 1)) {} /* { dg-warning "logical .and. of equal expressions" } */
40 if ((10 * a
) && (a
* 10)) {} /* { dg-warning "logical .and. of equal expressions" } */
41 if (!!a
&& a
) {} /* { dg-warning "logical .and. of equal expressions" } */
43 if (*p
&& *p
) {} /* { dg-warning "logical .and. of equal expressions" } */
44 if (p
[0] && p
[0]) {} /* { dg-warning "logical .and. of equal expressions" } */
45 if (S
.a
&& S
.a
) {} /* { dg-warning "logical .and. of equal expressions" } */
46 if ((bool) a
&& (bool) a
) {} /* { dg-warning "logical .and. of equal expressions" } */
47 if ((uint32_t) a
&& a
) {} /* { dg-warning "logical .and. of equal expressions" } */
49 /* Stay quiet here. */
53 if (a
> 0 && b
> 0) {}
54 if (a
< 0 && b
< 0) {}
55 if (a
== 0 && b
== 0) {}
56 if (a
<= 0 && b
<= 0) {}
57 if (a
>= 0 && b
>= 0) {}
59 if (a
> 0 && a
> 1) {}
60 if (a
> -2 && a
> 1) {}
61 if (a
&& (int16_t) a
) {}
67 if (bar () && bar ()) {}
74 orfn (int32_t a
, int32_t b
)
76 if (a
|| a
) {} /* { dg-warning "logical .or. of equal expressions" } */
77 if (!a
|| !a
) {} /* { dg-warning "logical .or. of equal expressions" } */
78 if (!!a
|| !!a
) {} /* { dg-warning "logical .or. of equal expressions" } */
79 if (a
> 0 || a
> 0) {} /* { dg-warning "logical .or. of equal expressions" } */
80 if (a
< 0 || a
< 0) {} /* { dg-warning "logical .or. of equal expressions" } */
81 if (a
== 0 || a
== 0) {} /* { dg-warning "logical .or. of equal expressions" } */
82 if (a
<= 0 || a
<= 0) {} /* { dg-warning "logical .or. of equal expressions" } */
83 if (a
>= 0 || a
>= 0) {} /* { dg-warning "logical .or. of equal expressions" } */
84 if (a
== 0 || !(a
!= 0)) {} /* { dg-warning "logical .or. of equal expressions" } */
86 if (a
|| a
|| a
) {} /* { dg-warning "logical .or. of equal expressions" } */
87 if ((a
+ 1) || (a
+ 1)) {} /* { dg-warning "logical .or. of equal expressions" } */
88 if ((10 * a
) || (a
* 10)) {} /* { dg-warning "logical .or. of equal expressions" } */
89 if (!!a
|| a
) {} /* { dg-warning "logical .or. of equal expressions" } */
91 if (*p
|| *p
) {} /* { dg-warning "logical .or. of equal expressions" } */
92 if (p
[0] || p
[0]) {} /* { dg-warning "logical .or. of equal expressions" } */
93 if (S
.a
|| S
.a
) {} /* { dg-warning "logical .or. of equal expressions" } */
94 if ((bool) a
|| (bool) a
) {} /* { dg-warning "logical .or. of equal expressions" } */
95 if ((uint32_t) a
|| a
) {} /* { dg-warning "logical .or. of equal expressions" } */
97 /* Stay quiet here. */
101 if (a
> 0 || b
> 0) {}
102 if (a
< 0 || b
< 0) {}
103 if (a
== 0 || b
== 0) {}
104 if (a
<= 0 || b
<= 0) {}
105 if (a
>= 0 || b
>= 0) {}
107 if (a
> 0 || a
> 1) {}
108 if (a
> -2 || a
> 1) {}
109 if (a
|| (int16_t) a
) {}
110 if ((char) a
|| a
) {}
115 if (bar () || bar ()) {}