blob: c56b6bc1595ad9187ed023780cd15c4dd33da92e [file] [log] [blame]
Richard Trieuf7432752014-06-06 21:39:26 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-bool-conversion %s
3// RUN: %clang_cc1 -fsyntax-only -verify -Wno-bool-conversion -Wundefined-bool-conversion %s
4// RUN: %clang_cc1 -fsyntax-only -verify -Wbool-conversion %s
5
6void test1(int &x) {
7 if (x == 1) { }
8 if (&x) { }
9 // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed always converted to true}}
10
11 if (!&x) { }
12 // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed always converted to true}}
13}
14
15class test2 {
16 test2() : x(y) {}
17
18 void foo() {
19 if (this) { }
20 // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; pointer may be assumed always converted to true}}
21
22 if (!this) { }
23 // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; pointer may be assumed always converted to true}}
24 }
25
26 void bar() {
27 if (x == 1) { }
28 if (&x) { }
29 // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed always converted to true}}
30
31 if (!&x) { }
32 // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed always converted to true}}
33 }
34
35 int &x;
36 int y;
37};