Douglas Gregor | 4038cf4 | 2010-06-08 17:35:15 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | |
Chandler Carruth | 66a7b04 | 2011-04-09 07:48:17 +0000 | [diff] [blame] | 3 | int* j = false; // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}} |
Douglas Gregor | 4038cf4 | 2010-06-08 17:35:15 +0000 | [diff] [blame] | 4 | |
Chandler Carruth | 66a7b04 | 2011-04-09 07:48:17 +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 | 4038cf4 | 2010-06-08 17:35:15 +0000 | [diff] [blame] | 6 | { |
Chandler Carruth | 66a7b04 | 2011-04-09 07:48:17 +0000 | [diff] [blame] | 7 | foo(false); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}} |
Chandler Carruth | ffab873 | 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 | |
Chandler Carruth | 66a7b04 | 2011-04-09 07:48:17 +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 | ffab873 | 2011-04-09 07:32:05 +0000 | [diff] [blame] | 13 | |
| 14 | const bool kFlag = false; |
Chandler Carruth | 66a7b04 | 2011-04-09 07:48:17 +0000 | [diff] [blame] | 15 | foo(kFlag); // expected-warning{{ initialization of pointer of type 'int *' to NULL from a constant boolean expression}} |
Douglas Gregor | 4038cf4 | 2010-06-08 17:35:15 +0000 | [diff] [blame] | 16 | } |
| 17 | |
Chandler Carruth | 477a999 | 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; |