blob: f6fa9f28369da410fc7060ff58e3881aa95e5f47 [file] [log] [blame]
Douglas Gregor4038cf42010-06-08 17:35:15 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
Chandler Carruth66a7b042011-04-09 07:48:17 +00003int* j = false; // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
Douglas Gregor4038cf42010-06-08 17:35:15 +00004
Chandler Carruth66a7b042011-04-09 07:48:17 +00005void foo(int* i, int *j=(false)) // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
Douglas Gregor4038cf42010-06-08 17:35:15 +00006{
Chandler Carruth66a7b042011-04-09 07:48:17 +00007 foo(false); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
Chandler Carruthffab8732011-04-09 07:32:05 +00008 foo((int*)false); // no-warning: explicit cast
9 foo(0); // no-warning: not a bool, even though its convertible to bool
10
Chandler Carruth66a7b042011-04-09 07:48:17 +000011 foo(false == true); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
12 foo((42 + 24) < 32); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
Chandler Carruthffab8732011-04-09 07:32:05 +000013
14 const bool kFlag = false;
Chandler Carruth66a7b042011-04-09 07:48:17 +000015 foo(kFlag); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}}
Douglas Gregor4038cf42010-06-08 17:35:15 +000016}
17
Chandler Carruth477a9992011-03-01 03:29:37 +000018char f(struct Undefined*);
19double f(...);
20
21// Ensure that when using false in metaprogramming machinery its conversion
22// isn't flagged.
23template <int N> struct S {};
24S<sizeof(f(false))> s;