Daily bump.
[official-gcc.git] / gcc / testsuite / gcc.dg / warn-addr-cmp.c
blob07491d1bb98f47a876a8b5581603571a3b6cb674
1 /* { dg-do compile } */
2 /* { dg-require-weak "" } */
3 /* { dg-options "-Waddress" } */
4 /* Warning when addr convert to bool always gives known result.
5 Ada/Pascal programmers sometimes write 0-param functions without
6 (), and might as well warn on variables, too. */
8 int func (void);
9 extern int var;
10 int weak_func (void) __attribute__ ((weak));
11 extern int weak_var __attribute__ ((weak));
13 int
14 test_func_cmp (void)
16 if (func) /* { dg-warning "the address of 'func'" } */
17 return 1;
18 if (!func) /* { dg-warning "the address of 'func'" } */
19 return 1;
20 if (&var) /* { dg-warning "the address of 'var'" } */
21 return 1;
22 if (!&var) /* { dg-warning "the address of 'var'" } */
23 return 1;
24 if (weak_func)
25 return 1;
26 if (!weak_func)
27 return 1;
28 if (&weak_var)
29 return 1;
30 if (!&weak_var)
31 return 1;
32 return 0;
35 /* Test equality with 0 on the right hand side. */
36 int
37 test_func_cmp_rhs_zero (void)
39 if (func == 0) /* { dg-warning "the comparison will always evaluate as 'false'" } */
40 return 1;
41 if (func != 0) /* { dg-warning "the comparison will always evaluate as 'true'" } */
42 return 1;
43 if (&var == 0) /* { dg-warning "the comparison will always evaluate as 'false'" } */
44 return 1;
45 if (&var != 0) /* { dg-warning "the comparison will always evaluate as 'true'" } */
46 return 1;
47 if (weak_func == 0)
48 return 1;
49 if (weak_func != 0)
50 return 1;
51 if (&weak_var == 0)
52 return 1;
53 if (&weak_var != 0)
54 return 1;
55 return 0;
58 /* Test equality with 0 on the left hand side. */
59 int
60 test_func_cmp_lhs_zero (void)
62 if (0 == func) /* { dg-warning "the comparison will always evaluate as 'false'" } */
63 return 1;
64 if (0 != func) /* { dg-warning "the comparison will always evaluate as 'true'" } */
65 return 1;
66 if (0 == &var) /* { dg-warning "the comparison will always evaluate as 'false'" } */
67 return 1;
68 if (0 != &var) /* { dg-warning "the comparison will always evaluate as 'true'" } */
69 return 1;
70 if (0 == weak_func)
71 return 1;
72 if (0 != weak_func)
73 return 1;
74 if (0 == &weak_var)
75 return 1;
76 if (0 != &weak_var)
77 return 1;
78 return 0;