Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fblocks -std=c++11 -verify %s |
Richard Trieu | 3e95ba9 | 2011-06-16 21:36:56 +0000 | [diff] [blame] | 2 | |
Chandler Carruth | 2af68e4 | 2011-06-19 09:05:14 +0000 | [diff] [blame] | 3 | void foo() { |
Richard Trieu | 3e95ba9 | 2011-06-16 21:36:56 +0000 | [diff] [blame] | 4 | int a; |
| 5 | bool b; |
| 6 | |
| 7 | a = 0 ? nullptr + a : a + nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 8 | a = 0 ? nullptr - a : a - nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 9 | a = 0 ? nullptr / a : a / nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 10 | a = 0 ? nullptr * a : a * nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 11 | a = 0 ? nullptr >> a : a >> nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 12 | a = 0 ? nullptr << a : a << nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 13 | a = 0 ? nullptr % a : a % nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 14 | a = 0 ? nullptr & a : a & nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 15 | a = 0 ? nullptr | a : a | nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 16 | a = 0 ? nullptr ^ a : a ^ nullptr; // expected-error 2{{invalid operands to binary expression}} |
| 17 | |
| 18 | // Using two nullptrs should only give one error instead of two. |
| 19 | a = nullptr + nullptr; // expected-error{{invalid operands to binary expression}} |
| 20 | a = nullptr - nullptr; // expected-error{{invalid operands to binary expression}} |
| 21 | a = nullptr / nullptr; // expected-error{{invalid operands to binary expression}} |
| 22 | a = nullptr * nullptr; // expected-error{{invalid operands to binary expression}} |
| 23 | a = nullptr >> nullptr; // expected-error{{invalid operands to binary expression}} |
| 24 | a = nullptr << nullptr; // expected-error{{invalid operands to binary expression}} |
| 25 | a = nullptr % nullptr; // expected-error{{invalid operands to binary expression}} |
| 26 | a = nullptr & nullptr; // expected-error{{invalid operands to binary expression}} |
| 27 | a = nullptr | nullptr; // expected-error{{invalid operands to binary expression}} |
| 28 | a = nullptr ^ nullptr; // expected-error{{invalid operands to binary expression}} |
| 29 | |
| 30 | a += nullptr; // expected-error{{invalid operands to binary expression}} |
| 31 | a -= nullptr; // expected-error{{invalid operands to binary expression}} |
| 32 | a /= nullptr; // expected-error{{invalid operands to binary expression}} |
| 33 | a *= nullptr; // expected-error{{invalid operands to binary expression}} |
| 34 | a >>= nullptr; // expected-error{{invalid operands to binary expression}} |
| 35 | a <<= nullptr; // expected-error{{invalid operands to binary expression}} |
| 36 | a %= nullptr; // expected-error{{invalid operands to binary expression}} |
| 37 | a &= nullptr; // expected-error{{invalid operands to binary expression}} |
| 38 | a |= nullptr; // expected-error{{invalid operands to binary expression}} |
| 39 | a ^= nullptr; // expected-error{{invalid operands to binary expression}} |
| 40 | |
| 41 | b = a < nullptr || nullptr < a; // expected-error 2{{invalid operands to binary expression}} |
| 42 | b = a > nullptr || nullptr > a; // expected-error 2{{invalid operands to binary expression}} |
| 43 | b = a <= nullptr || nullptr <= a; // expected-error 2{{invalid operands to binary expression}} |
| 44 | b = a >= nullptr || nullptr >= a; // expected-error 2{{invalid operands to binary expression}} |
| 45 | b = a == nullptr || nullptr == a; // expected-error 2{{invalid operands to binary expression}} |
| 46 | b = a != nullptr || nullptr != a; // expected-error 2{{invalid operands to binary expression}} |
| 47 | |
| 48 | b = &a < nullptr || nullptr < &a || &a > nullptr || nullptr > &a; |
| 49 | b = &a <= nullptr || nullptr <= &a || &a >= nullptr || nullptr >= &a; |
| 50 | b = &a == nullptr || nullptr == &a || &a != nullptr || nullptr != &a; |
| 51 | |
Chandler Carruth | 2af68e4 | 2011-06-19 09:05:14 +0000 | [diff] [blame] | 52 | b = nullptr < nullptr || nullptr > nullptr; |
| 53 | b = nullptr <= nullptr || nullptr >= nullptr; |
| 54 | b = nullptr == nullptr || nullptr != nullptr; |
Richard Trieu | 3e95ba9 | 2011-06-16 21:36:56 +0000 | [diff] [blame] | 55 | |
| 56 | b = ((nullptr)) != a; // expected-error{{invalid operands to binary expression}} |
| 57 | |
| 58 | void (^c)(); |
| 59 | c = nullptr; |
| 60 | b = c == nullptr || nullptr == c || c != nullptr || nullptr != c; |
| 61 | |
| 62 | class X; |
| 63 | void (X::*d) (); |
| 64 | d = nullptr; |
| 65 | b = d == nullptr || nullptr == d || d != nullptr || nullptr != d; |
Chandler Carruth | 2af68e4 | 2011-06-19 09:05:14 +0000 | [diff] [blame] | 66 | |
| 67 | extern void e(); |
| 68 | b = e == nullptr || nullptr == e || e != nullptr || nullptr != e; |
| 69 | |
| 70 | int f[2]; |
| 71 | b = f == nullptr || nullptr == f || f != nullptr || nullptr != f; |
| 72 | b = "f" == nullptr || nullptr == "f" || "f" != nullptr || nullptr != "f"; |
Richard Trieu | 3e95ba9 | 2011-06-16 21:36:56 +0000 | [diff] [blame] | 73 | } |