Douglas Gregor | d7a9597 | 2010-06-08 17:35:15 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 3 | int* j = false; // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}} |
Douglas Gregor | d7a9597 | 2010-06-08 17:35:15 +0000 | [diff] [blame] | 4 | |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 5 | void foo(int* i, int *j=(false)) // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}} |
Douglas Gregor | d7a9597 | 2010-06-08 17:35:15 +0000 | [diff] [blame] | 6 | { |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 7 | foo(false); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}} |
Chandler Carruth | 88f0aed | 2011-04-09 07:32:05 +0000 | [diff] [blame] | 8 | foo((int*)false); // no-warning: explicit cast |
| 9 | foo(0); // no-warning: not a bool, even though its convertible to bool |
| 10 | |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 11 | 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 Carruth | 88f0aed | 2011-04-09 07:32:05 +0000 | [diff] [blame] | 13 | |
| 14 | const bool kFlag = false; |
Richard Trieu | 2fe9b7f | 2011-12-15 00:38:15 +0000 | [diff] [blame] | 15 | foo(kFlag); // expected-warning{{initialization of pointer of type 'int *' to null from a constant boolean expression}} |
Douglas Gregor | d7a9597 | 2010-06-08 17:35:15 +0000 | [diff] [blame] | 16 | } |
| 17 | |
Chandler Carruth | e34e3f1 | 2011-03-01 03:29:37 +0000 | [diff] [blame] | 18 | char f(struct Undefined*); |
| 19 | double f(...); |
| 20 | |
| 21 | // Ensure that when using false in metaprogramming machinery its conversion |
| 22 | // isn't flagged. |
| 23 | template <int N> struct S {}; |
| 24 | S<sizeof(f(false))> s; |