diff options
author | dim <dim@FreeBSD.org> | 2011-07-17 15:40:56 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-07-17 15:40:56 +0000 |
commit | 611ba3ea3300b71eb95dc4e45f20eee5dddd32e1 (patch) | |
tree | 2097d084eb235c0b12c0bff3445f4ec7bbaa8a12 /test/SemaCXX/null_in_arithmetic_ops.cpp | |
parent | c49018d9cce52d8c9f34b44865ec3ba8e89a1488 (diff) | |
download | FreeBSD-src-611ba3ea3300b71eb95dc4e45f20eee5dddd32e1.zip FreeBSD-src-611ba3ea3300b71eb95dc4e45f20eee5dddd32e1.tar.gz |
Vendor import of clang trunk r135360:
http://llvm.org/svn/llvm-project/cfe/trunk@135360
Diffstat (limited to 'test/SemaCXX/null_in_arithmetic_ops.cpp')
-rw-r--r-- | test/SemaCXX/null_in_arithmetic_ops.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/test/SemaCXX/null_in_arithmetic_ops.cpp b/test/SemaCXX/null_in_arithmetic_ops.cpp new file mode 100644 index 0000000..fab6f10 --- /dev/null +++ b/test/SemaCXX/null_in_arithmetic_ops.cpp @@ -0,0 +1,93 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -fblocks -Wnull-arithmetic -verify %s +#include <stddef.h> + +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}} + a = 0 ? NULL / a : a / NULL; // expected-warning 2{{use of NULL in arithmetic operation}} \ + // expected-warning {{division by zero is undefined}} + 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}} + 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}} \ + expected-warning {{remainder by zero is undefined}} + 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}} + 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 a pointer to the function type 'void ()'}} + 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}} + a = NULL / NULL; // expected-warning{{use of NULL in arithmetic operation}} \ + // expected-warning{{division by zero is undefined}} + a = NULL * NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL >> NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL << NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL % NULL; // expected-warning{{use of NULL in arithmetic operation}} \ + // expected-warning{{remainder by zero is undefined}} + a = NULL & NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL | NULL; // expected-warning{{use of NULL in arithmetic operation}} + a = NULL ^ NULL; // expected-warning{{use of NULL in arithmetic operation}} + + a += NULL; // expected-warning{{use of NULL in arithmetic operation}} + a -= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a /= NULL; // expected-warning{{use of NULL in arithmetic operation}} \ + // expected-warning{{division by zero is undefined}} + a *= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a >>= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a <<= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a %= NULL; // expected-warning{{use of NULL in arithmetic operation}} \ + // expected-warning{{remainder by zero is undefined}} + a &= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a |= NULL; // expected-warning{{use of NULL in arithmetic operation}} + a ^= NULL; // expected-warning{{use of NULL in arithmetic operation}} + + b = a < NULL || NULL < a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a > NULL || NULL > a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a <= NULL || NULL <= a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a >= NULL || NULL >= a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a == NULL || NULL == a; // expected-warning 2{{use of NULL in arithmetic operation}} + b = a != NULL || NULL != a; // expected-warning 2{{use of NULL in arithmetic operation}} + + b = &a < NULL || NULL < &a || &a > NULL || NULL > &a; + b = &a <= NULL || NULL <= &a || &a >= NULL || NULL >= &a; + b = &a == NULL || NULL == &a || &a != NULL || NULL != &a; + + b = 0 == a; + b = 0 == &a; + + b = NULL < NULL || NULL > NULL; + b = NULL <= NULL || NULL >= NULL; + b = NULL == NULL || NULL != NULL; + + b = ((NULL)) != a; // expected-warning{{use of NULL in arithmetic operation}} + + // Check that even non-standard pointers don't warn. + b = c == NULL || NULL == c || c != NULL || NULL != c; + b = d == NULL || NULL == d || d != NULL || NULL != d; + b = e == NULL || NULL == e || e != NULL || NULL != e; + b = f == NULL || NULL == f || f != NULL || NULL != f; + b = "f" == NULL || NULL == "f" || "f" != NULL || NULL != "f"; +} |