blob: 547c936c3e558fd2108f677af3e7e8aee23150c0 [file] [log] [blame]
Richard Trieu701fb362011-06-16 21:36:56 +00001// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
2#include <stddef.h>
3
4void f() {
5 int a;
6 bool b;
7
8 a = 0 ? NULL + a : a + NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
9 a = 0 ? NULL - a : a - NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
10 a = 0 ? NULL / a : a / NULL; // expected-warning 2{{use of NULL in arithmetic operation}} \
11 // expected-warning {{division by zero is undefined}}
12 a = 0 ? NULL * a : a * NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
13 a = 0 ? NULL >> a : a >> NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
14 a = 0 ? NULL << a : a << NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
15 a = 0 ? NULL % a : a % NULL; // expected-warning 2{{use of NULL in arithmetic operation}} \
16 expected-warning {{remainder by zero is undefined}}
17 a = 0 ? NULL & a : a & NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
18 a = 0 ? NULL | a : a | NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
19 a = 0 ? NULL ^ a : a ^ NULL; // expected-warning 2{{use of NULL in arithmetic operation}}
20
21 // Using two NULLs should only give one error instead of two.
22 a = NULL + NULL; // expected-warning{{use of NULL in arithmetic operation}}
23 a = NULL - NULL; // expected-warning{{use of NULL in arithmetic operation}}
24 a = NULL / NULL; // expected-warning{{use of NULL in arithmetic operation}} \
25 // expected-warning{{division by zero is undefined}}
26 a = NULL * NULL; // expected-warning{{use of NULL in arithmetic operation}}
27 a = NULL >> NULL; // expected-warning{{use of NULL in arithmetic operation}}
28 a = NULL << NULL; // expected-warning{{use of NULL in arithmetic operation}}
29 a = NULL % NULL; // expected-warning{{use of NULL in arithmetic operation}} \
30 // expected-warning{{remainder by zero is undefined}}
31 a = NULL & NULL; // expected-warning{{use of NULL in arithmetic operation}}
32 a = NULL | NULL; // expected-warning{{use of NULL in arithmetic operation}}
33 a = NULL ^ NULL; // expected-warning{{use of NULL in arithmetic operation}}
34
35 a += NULL; // expected-warning{{use of NULL in arithmetic operation}}
36 a -= NULL; // expected-warning{{use of NULL in arithmetic operation}}
37 a /= NULL; // expected-warning{{use of NULL in arithmetic operation}} \
38 // expected-warning{{division by zero is undefined}}
39 a *= NULL; // expected-warning{{use of NULL in arithmetic operation}}
40 a >>= NULL; // expected-warning{{use of NULL in arithmetic operation}}
41 a <<= NULL; // expected-warning{{use of NULL in arithmetic operation}}
42 a %= NULL; // expected-warning{{use of NULL in arithmetic operation}} \
43 // expected-warning{{remainder by zero is undefined}}
44 a &= NULL; // expected-warning{{use of NULL in arithmetic operation}}
45 a |= NULL; // expected-warning{{use of NULL in arithmetic operation}}
46 a ^= NULL; // expected-warning{{use of NULL in arithmetic operation}}
47
48 b = a < NULL || NULL < a; // expected-warning 2{{use of NULL in arithmetic operation}}
49 b = a > NULL || NULL > a; // expected-warning 2{{use of NULL in arithmetic operation}}
50 b = a <= NULL || NULL <= a; // expected-warning 2{{use of NULL in arithmetic operation}}
51 b = a >= NULL || NULL >= a; // expected-warning 2{{use of NULL in arithmetic operation}}
52 b = a == NULL || NULL == a; // expected-warning 2{{use of NULL in arithmetic operation}}
53 b = a != NULL || NULL != a; // expected-warning 2{{use of NULL in arithmetic operation}}
54
55 b = &a < NULL || NULL < &a || &a > NULL || NULL > &a;
56 b = &a <= NULL || NULL <= &a || &a >= NULL || NULL >= &a;
57 b = &a == NULL || NULL == &a || &a != NULL || NULL != &a;
58
59 b = 0 == a;
60 b = 0 == &a;
61
62 b = ((NULL)) != a; // expected-warning{{use of NULL in arithmetic operation}}
63
64 void (^c)();
65 b = c == NULL || NULL == c || c != NULL || NULL != c;
66
67 class X;
68 void (X::*d) ();
69 b = d == NULL || NULL == d || d != NULL || NULL != d;
70}