summaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/nullptr_in_arithmetic_ops.cpp
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/SemaCXX/nullptr_in_arithmetic_ops.cpp
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/SemaCXX/nullptr_in_arithmetic_ops.cpp')
-rw-r--r--clang/test/SemaCXX/nullptr_in_arithmetic_ops.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/nullptr_in_arithmetic_ops.cpp b/clang/test/SemaCXX/nullptr_in_arithmetic_ops.cpp
new file mode 100644
index 0000000..9671353
--- /dev/null
+++ b/clang/test/SemaCXX/nullptr_in_arithmetic_ops.cpp
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -std=c++11 -verify %s
+
+void foo() {
+ int a;
+ bool b;
+
+ a = 0 ? nullptr + a : a + nullptr; // expected-error 2{{invalid operands to binary expression}}
+ a = 0 ? nullptr - a : a - nullptr; // expected-error 2{{invalid operands to binary expression}}
+ a = 0 ? nullptr / a : a / nullptr; // expected-error 2{{invalid operands to binary expression}}
+ a = 0 ? nullptr * a : a * nullptr; // expected-error 2{{invalid operands to binary expression}}
+ a = 0 ? nullptr >> a : a >> nullptr; // expected-error 2{{invalid operands to binary expression}}
+ a = 0 ? nullptr << a : a << nullptr; // expected-error 2{{invalid operands to binary expression}}
+ a = 0 ? nullptr % a : a % nullptr; // expected-error 2{{invalid operands to binary expression}}
+ a = 0 ? nullptr & a : a & nullptr; // expected-error 2{{invalid operands to binary expression}}
+ a = 0 ? nullptr | a : a | nullptr; // expected-error 2{{invalid operands to binary expression}}
+ a = 0 ? nullptr ^ a : a ^ nullptr; // expected-error 2{{invalid operands to binary expression}}
+
+ // Using two nullptrs should only give one error instead of two.
+ a = nullptr + nullptr; // expected-error{{invalid operands to binary expression}}
+ a = nullptr - nullptr; // expected-error{{invalid operands to binary expression}}
+ a = nullptr / nullptr; // expected-error{{invalid operands to binary expression}}
+ a = nullptr * nullptr; // expected-error{{invalid operands to binary expression}}
+ a = nullptr >> nullptr; // expected-error{{invalid operands to binary expression}}
+ a = nullptr << nullptr; // expected-error{{invalid operands to binary expression}}
+ a = nullptr % nullptr; // expected-error{{invalid operands to binary expression}}
+ a = nullptr & nullptr; // expected-error{{invalid operands to binary expression}}
+ a = nullptr | nullptr; // expected-error{{invalid operands to binary expression}}
+ a = nullptr ^ nullptr; // expected-error{{invalid operands to binary expression}}
+
+ a += nullptr; // expected-error{{invalid operands to binary expression}}
+ a -= nullptr; // expected-error{{invalid operands to binary expression}}
+ a /= nullptr; // expected-error{{invalid operands to binary expression}}
+ a *= nullptr; // expected-error{{invalid operands to binary expression}}
+ a >>= nullptr; // expected-error{{invalid operands to binary expression}}
+ a <<= nullptr; // expected-error{{invalid operands to binary expression}}
+ a %= nullptr; // expected-error{{invalid operands to binary expression}}
+ a &= nullptr; // expected-error{{invalid operands to binary expression}}
+ a |= nullptr; // expected-error{{invalid operands to binary expression}}
+ a ^= nullptr; // expected-error{{invalid operands to binary expression}}
+
+ b = a < nullptr || nullptr < a; // expected-error 2{{invalid operands to binary expression}}
+ b = a > nullptr || nullptr > a; // expected-error 2{{invalid operands to binary expression}}
+ b = a <= nullptr || nullptr <= a; // expected-error 2{{invalid operands to binary expression}}
+ b = a >= nullptr || nullptr >= a; // expected-error 2{{invalid operands to binary expression}}
+ b = a == nullptr || nullptr == a; // expected-error 2{{invalid operands to binary expression}}
+ b = a != nullptr || nullptr != a; // expected-error 2{{invalid operands to binary expression}}
+
+ b = &a < nullptr || nullptr < &a || &a > nullptr || nullptr > &a;
+ b = &a <= nullptr || nullptr <= &a || &a >= nullptr || nullptr >= &a;
+ b = &a == nullptr || nullptr == &a || &a != nullptr || nullptr != &a;
+
+ b = nullptr < nullptr || nullptr > nullptr;
+ b = nullptr <= nullptr || nullptr >= nullptr;
+ b = nullptr == nullptr || nullptr != nullptr;
+
+ b = ((nullptr)) != a; // expected-error{{invalid operands to binary expression}}
+
+ void (^c)();
+ c = nullptr;
+ b = c == nullptr || nullptr == c || c != nullptr || nullptr != c;
+
+ class X;
+ void (X::*d) ();
+ d = nullptr;
+ b = d == nullptr || nullptr == d || d != nullptr || nullptr != d;
+
+ extern void e();
+ b = e == nullptr || nullptr == e || e != nullptr || nullptr != e;
+
+ int f[2];
+ b = f == nullptr || nullptr == f || f != nullptr || nullptr != f;
+ b = "f" == nullptr || nullptr == "f" || "f" != nullptr || nullptr != "f";
+}