Fix test-suite fallout of default -Wreturn-type.
[official-gcc.git] / gcc / testsuite / g++.dg / warn / Wconversion-null-2.C
blob98f5c4051651d62046f5459d2259c50ee1f1ee6e
1 // { dg-do link  }
2 // { dg-options "" }
4 #include <cstddef>
6 void g(int) {}
7 void g(long) {}
8 void g(long long) {}
9 extern void g(void*);
11 template <int I>
12 void h() {}
14 void k(int) {}
16 template <class T>
17 void l(T);
19 template <>
20 void l(int) {}
22 template <>
23 void l(long) {}
25 template <>
26 void l(long long) {}
28 void warn_for_NULL()
30   int i = NULL; // { dg-warning "" } converting NULL to non-pointer type
31   float z = NULL; // { dg-warning "" } converting NULL to non-pointer type
32   int a[2];
34   i != NULL; // { dg-warning "" } NULL used in arithmetic
35   NULL != z; // { dg-warning "" } NULL used in arithmetic
36   k != NULL; // No warning: decay conversion
37   NULL != a; // Likewise.
38   -NULL;     // { dg-warning "" } converting NULL to non-pointer type
39   +NULL;     // { dg-warning "" } converting NULL to non-pointer type
40   ~NULL;     // { dg-warning "" } converting NULL to non-pointer type
41   a[NULL] = 3; // { dg-warning "" } converting NULL to non-pointer-type
42   i = NULL;  // { dg-warning "" } converting NULL to non-pointer type
43   z = NULL;  // { dg-warning "" } converting NULL to non-pointer type
44   k(NULL);   // { dg-warning "" } converting NULL to int
45   g(NULL);   // { dg-warning "" } converting NULL to int
46   h<NULL>(); // No warning: NULL bound to integer template parameter
47   l(NULL);   // No warning: NULL is used to implicitly instantiate the template
48   NULL && NULL; // No warning: converting NULL to bool is OK
51 void warn_for___null()
53   int i = __null; // { dg-warning "" } converting __null to non-pointer type
54   float z = __null; // { dg-warning "" } converting __null to non-pointer type
55   int a[2];
57   i != __null; // { dg-warning "" } __null used in arithmetic
58   __null != z; // { dg-warning "" } __null used in arithmetic
59   k != __null; // No warning: decay conversion
60   __null != a; // Likewise.
61   -__null;     // { dg-warning "" } converting __null to non-pointer type
62   +__null;     // { dg-warning "" } converting __null to non-pointer type
63   ~__null;     // { dg-warning "" } converting __null to non-pointer type
64   a[__null] = 3; // { dg-warning "" } converting __null to non-pointer-type
65   i = __null;  // { dg-warning "" } converting __null to non-pointer type
66   z = __null;  // { dg-warning "" } converting __null to non-pointer type
67   k(__null);   // { dg-warning "" } converting __null to int
68   g(__null);   // { dg-warning "" } converting __null to int
69   h<__null>(); // No warning: __null bound to integer template parameter
70   l(__null);   // No warning: __null is used to implicitly instantiate the template
71   __null && __null; // No warning: converting NULL to bool is OK
74 int main()
76   warn_for_NULL();
77   warn_for___null();