| Richard Trieu | f743275 | 2014-06-06 21:39:26 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 | // RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-undefined-compare %s |
| 3 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-tautological-compare -Wtautological-undefined-compare %s |
| 4 | // RUN: %clang_cc1 -fsyntax-only -verify -Wtautological-compare %s |
| 5 | |
| 6 | void test1(int &x) { |
| 7 | if (x == 1) { } |
| 8 | if (&x == 0) { } |
| 9 | // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to false}} |
| 10 | if (&x != 0) { } |
| 11 | // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}} |
| 12 | } |
| 13 | |
| 14 | class test2 { |
| 15 | test2() : x(y) {} |
| 16 | |
| 17 | void foo() { |
| 18 | if (this == 0) { } |
| 19 | // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to false}} |
| 20 | if (this != 0) { } |
| 21 | // expected-warning@-1{{'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to true}} |
| 22 | } |
| 23 | |
| 24 | void bar() { |
| 25 | if (x == 1) { } |
| 26 | if (&x == 0) { } |
| 27 | // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to false}} |
| 28 | if (&x != 0) { } |
| 29 | // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}} |
| 30 | } |
| 31 | |
| 32 | int &x; |
| 33 | int y; |
| 34 | }; |