1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 namespace BooleanFalse {
4 int* j = false; // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
6 void foo(int* i, int *j=(false)) // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
8 foo(false); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
9 foo((int*)false); // no-warning: explicit cast
10 foo(0); // no-warning: not a bool, even though its convertible to bool
12 foo(false == true); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
13 foo((42 + 24) < 32); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
15 const bool kFlag = false;
16 foo(kFlag); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
19 char f(struct Undefined*);
22 // Ensure that when using false in metaprogramming machinery its conversion
24 template <int N> struct S {};
25 S<sizeof(f(false))> s;
36 extern void f3() __attribute__((weak_import));
39 static void f4() __attribute__((weak_import));
48 b = f1; // expected-warning {{address of function 'f1' will always evaluate to 'true'}} \
49 expected-note {{prefix with the address-of operator to silence this warning}}
50 if (f1) {} // expected-warning {{address of function 'f1' will always evaluate to 'true'}} \
51 expected-note {{prefix with the address-of operator to silence this warning}}
52 b = S::f2; // expected-warning {{address of function 'S::f2' will always evaluate to 'true'}} \
53 expected-note {{prefix with the address-of operator to silence this warning}}
54 if (S::f2) {} // expected-warning {{address of function 'S::f2' will always evaluate to 'true'}} \
55 expected-note {{prefix with the address-of operator to silence this warning}}
56 b = f5; // expected-warning {{address of function 'f5' will always evaluate to 'true'}} \
57 expected-note {{prefix with the address-of operator to silence this warning}} \
58 expected-note {{suffix with parentheses to turn this into a function call}}
59 b = f6; // expected-warning {{address of function 'f6' will always evaluate to 'true'}} \
60 expected-note {{prefix with the address-of operator to silence this warning}}
62 // implicit casts of weakly imported symbols are ok:
71 #define GetValue(ptr) ((ptr) ? ptr[0] : 0)
72 extern int a[] __attribute__((weak));
77 const char str[] = "text";
85 // expected-warning@-1{{address of array 'b' will always evaluate to 'true'}}
87 // expected-warning@-1{{address of array 'b' will always evaluate to 'true'}}
89 // expected-warning@-1{{address of array 'c.x' will always evaluate to 'true'}}
91 // expected-warning@-1{{address of array 'str' will always evaluate to 'true'}}
96 extern int a __attribute__((weak));
110 // expected-warning@-1{{address of 'b' will always evaluate to 'true'}}
112 // expected-warning@-1{{address of 'c' will always evaluate to 'true'}}
114 // expected-warning@-1{{address of 's.a' will always evaluate to 'true'}}
116 // expected-warning@-1{{address of 's.b' will always evaluate to 'true'}}
118 // expected-warning@-1{{address of 'S::a' will always evaluate to 'true'}}
123 #define assert(x) if (x) {}
124 #define zero_on_null(x) ((x) ? *(x) : 0)
132 assert(array && "expecting null pointer");
133 // expected-warning@-1{{address of array 'array' will always evaluate to 'true'}}
136 assert(fun && "expecting null pointer");
137 // expected-warning@-1{{address of function 'fun' will always evaluate to 'true'}}
138 // expected-note@-2 {{prefix with the address-of operator to silence this warning}}
140 // TODO: warn on assert(&x) while not warning on zero_on_null(&x)
142 assert(zero_on_null(&x));
144 assert(&x && "expecting null pointer");
145 // expected-warning@-1{{address of 'x' will always evaluate to 'true'}}