summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/null_in_arithmetic_ops.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-06-20 07:38:51 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-06-20 07:38:51 +0000
commit4f04b436f8a516d2ee9c2972d6d7080cf037649a (patch)
tree704708456dcf8d157468fcb407fd5f72da6f00c2 /clang/test/SemaCXX/null_in_arithmetic_ops.cpp
parentd34ce4344be3cf6c84e59baba09ef7aa742973c3 (diff)
downloadbcm5719-llvm-4f04b436f8a516d2ee9c2972d6d7080cf037649a.tar.gz
bcm5719-llvm-4f04b436f8a516d2ee9c2972d6d7080cf037649a.zip
Move away from the poor "abstraction" I added to Type. John argued
effectively that this abstraction simply doesn't exist. That is highlighted by the fact that by using it we were papering over a more serious error in this warning: the fact that we warned for *invalid* constructs involving member pointers and block pointers. I've fixed the obvious issues with the warning here, but this is confirming an original suspicion that this warning's implementation is flawed. I'm looking into how we can implement this more reasonably. WIP on that front. llvm-svn: 133425
Diffstat (limited to 'clang/test/SemaCXX/null_in_arithmetic_ops.cpp')
-rw-r--r--clang/test/SemaCXX/null_in_arithmetic_ops.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/clang/test/SemaCXX/null_in_arithmetic_ops.cpp b/clang/test/SemaCXX/null_in_arithmetic_ops.cpp
index 78c76e7e4c2..9665c3959e7 100644
--- a/clang/test/SemaCXX/null_in_arithmetic_ops.cpp
+++ b/clang/test/SemaCXX/null_in_arithmetic_ops.cpp
@@ -4,6 +4,12 @@
void f() {
int a;
bool b;
+ void (^c)();
+ class X;
+ void (X::*d) ();
+ extern void e();
+ int f[2];
+ const void *v;
a = 0 ? NULL + a : a + NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
a = 0 ? NULL - a : a - NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
@@ -18,6 +24,19 @@ void f() {
a = 0 ? NULL | a : a | NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
a = 0 ? NULL ^ a : a ^ NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
+ // Check for warnings or errors when doing arithmetic on pointers and other
+ // types.
+ v = 0 ? NULL + &a : &a + NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
+ v = 0 ? NULL + c : c + NULL; // \
+ expected-error {{invalid operands to binary expression ('long' and 'void (^)()')}} \
+ expected-error {{invalid operands to binary expression ('void (^)()' and 'long')}}
+ v = 0 ? NULL + d : d + NULL; // \
+ expected-error {{invalid operands to binary expression ('long' and 'void (X::*)()')}} \
+ expected-error {{invalid operands to binary expression ('void (X::*)()' and 'long')}}
+ v = 0 ? NULL + e : e + NULL; // expected-error 2{{arithmetic on pointer to function type}}
+ v = 0 ? NULL + f : f + NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
+ v = 0 ? NULL + "f" : "f" + NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
+
// Using two NULLs should only give one error instead of two.
a = NULL + NULL; // expected-warning{{use of NULL in arithmetic operation}}
a = NULL - NULL; // expected-warning{{use of NULL in arithmetic operation}}
@@ -65,17 +84,10 @@ void f() {
b = ((NULL)) != a; // expected-warning{{use of NULL in arithmetic operation}}
- void (^c)();
+ // Check that even non-standard pointers don't warn.
b = c == NULL || NULL == c || c != NULL || NULL != c;
-
- class X;
- void (X::*d) ();
b = d == NULL || NULL == d || d != NULL || NULL != d;
-
- extern void e();
b = e == NULL || NULL == e || e != NULL || NULL != e;
-
- int f[2];
b = f == NULL || NULL == f || f != NULL || NULL != f;
b = "f" == NULL || NULL == "f" || "f" != NULL || NULL != "f";
}
OpenPOWER on IntegriCloud