Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wconversion-null-2.C

raw
1 // { dg-do link }
2 // { dg-options "" }
3
4 #include <cstddef>
5
6 void g(int) {}
7 void g(long) {}
8 void g(long long) {}
9 #ifdef __MSP430X_LARGE__
10 void g(__int20) {}
11 #endif
12 extern void g(void*);
13
14 template <int I>
15 void h() {}
16
17 void k(int) {}
18
19 template <class T>
20 void l(T);
21
22 template <>
23 void l(int) {}
24
25 template <>
26 void l(long) {}
27
28 template <>
29 void l(long long) {}
30
31 #ifdef __MSP430X_LARGE__
32 template <>
33 void l(__int20) {}
34 #endif
35
36 void warn_for_NULL()
37 {
38 int i = NULL; // { dg-warning "" } converting NULL to non-pointer type
39 float z = NULL; // { dg-warning "" } converting NULL to non-pointer type
40 int a[2];
41
42 i != NULL; // { dg-warning "" } NULL used in arithmetic
43 NULL != z; // { dg-warning "" } NULL used in arithmetic
44 k != NULL; // No warning: decay conversion
45 NULL != a; // Likewise.
46 -NULL; // { dg-warning "" } converting NULL to non-pointer type
47 +NULL; // { dg-warning "" } converting NULL to non-pointer type
48 ~NULL; // { dg-warning "" } converting NULL to non-pointer type
49 a[NULL] = 3; // { dg-warning "" } converting NULL to non-pointer-type
50 i = NULL; // { dg-warning "" } converting NULL to non-pointer type
51 z = NULL; // { dg-warning "" } converting NULL to non-pointer type
52 k(NULL); // { dg-warning "" } converting NULL to int
53 g(NULL); // { dg-warning "" } converting NULL to int
54 h<NULL>(); // No warning: NULL bound to integer template parameter
55 l(NULL); // No warning: NULL is used to implicitly instantiate the template
56 NULL && NULL; // No warning: converting NULL to bool is OK
57 }
58
59 void warn_for___null()
60 {
61 int i = __null; // { dg-warning "" } converting __null to non-pointer type
62 float z = __null; // { dg-warning "" } converting __null to non-pointer type
63 int a[2];
64
65 i != __null; // { dg-warning "" } __null used in arithmetic
66 __null != z; // { dg-warning "" } __null used in arithmetic
67 k != __null; // No warning: decay conversion
68 __null != a; // Likewise.
69 -__null; // { dg-warning "" } converting __null to non-pointer type
70 +__null; // { dg-warning "" } converting __null to non-pointer type
71 ~__null; // { dg-warning "" } converting __null to non-pointer type
72 a[__null] = 3; // { dg-warning "" } converting __null to non-pointer-type
73 i = __null; // { dg-warning "" } converting __null to non-pointer type
74 z = __null; // { dg-warning "" } converting __null to non-pointer type
75 k(__null); // { dg-warning "" } converting __null to int
76 g(__null); // { dg-warning "" } converting __null to int
77 h<__null>(); // No warning: __null bound to integer template parameter
78 l(__null); // No warning: __null is used to implicitly instantiate the template
79 __null && __null; // No warning: converting NULL to bool is OK
80 }
81
82 int main()
83 {
84 warn_for_NULL();
85 warn_for___null();
86 }