blob: b3d136ecf2b13b05811a1e58e0973d3fd327eb25 [file] [log] [blame]
Douglas Gregord7a95972010-06-08 17:35:15 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2
Richard Trieu2fe9b7f2011-12-15 00:38:15 +00003int* j = false; // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
Douglas Gregord7a95972010-06-08 17:35:15 +00004
Richard Trieu2fe9b7f2011-12-15 00:38:15 +00005void foo(int* i, int *j=(false)) // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
Douglas Gregord7a95972010-06-08 17:35:15 +00006{
Richard Trieu2fe9b7f2011-12-15 00:38:15 +00007 foo(false); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
Chandler Carruth88f0aed2011-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
Richard Trieu2fe9b7f2011-12-15 00:38:15 +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 Carruth88f0aed2011-04-09 07:32:05 +000013
14 const bool kFlag = false;
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000015 foo(kFlag); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}}
Douglas Gregord7a95972010-06-08 17:35:15 +000016}
17
Chandler Carruthe34e3f12011-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;