| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-std=c23 -Wzero-as-null-pointer-constant" } */ |
| 3 |
|
| 4 |
#define NULL (void*)0 |
| 5 |
|
| 6 |
void foo(void*); |
| 7 |
void baz(bool); |
| 8 |
|
| 9 |
void bar() |
| 10 |
{ |
| 11 |
foo(0); /* { dg-warning "zero as null pointer constant" } */ |
| 12 |
foo(NULL); |
| 13 |
foo(nullptr); |
| 14 |
|
| 15 |
int a = 0; |
| 16 |
|
| 17 |
bool b = 0; |
| 18 |
bool c = (void*)0; |
| 19 |
bool d = NULL; |
| 20 |
bool e = nullptr; |
| 21 |
|
| 22 |
bool f = (bool)0; |
| 23 |
bool g = (bool)(void*)0; |
| 24 |
bool h = (bool)NULL; |
| 25 |
bool i = (bool)nullptr; |
| 26 |
|
| 27 |
baz(0); |
| 28 |
baz((void*)0); |
| 29 |
baz(NULL); |
| 30 |
baz(nullptr); |
| 31 |
baz((bool)0); |
| 32 |
baz((bool)(void*)0); |
| 33 |
baz((bool)NULL); |
| 34 |
baz((bool)nullptr); |
| 35 |
|
| 36 |
void *p = 0; /* { dg-warning "zero as null pointer constant" } */ |
| 37 |
void *r = NULL; |
| 38 |
void *t = nullptr; |
| 39 |
void *o = { }; |
| 40 |
void *q = { 0 }; /* { dg-warning "zero as null pointer constant" } */ |
| 41 |
void *s = { NULL }; |
| 42 |
void *u = { nullptr }; |
| 43 |
struct { void *q; } x = { 0 }; /* { dg-warning "zero as null pointer constant" } */ |
| 44 |
struct { void *q; } y = { NULL }; |
| 45 |
struct { void *q; } z = { nullptr }; |
| 46 |
struct { int a; void *b; } n = { 0 }; |
| 47 |
struct { int a; int b; void *c; } m = { 0, 0 }; |
| 48 |
|
| 49 |
1 ? 0 : 0; |
| 50 |
1 ? i : 0; |
| 51 |
1 ? 0 : p; /* { dg-warning "zero as null pointer constant" } */ |
| 52 |
1 ? p : 0; /* { dg-warning "zero as null pointer constant" } */ |
| 53 |
1 ? 0 : NULL; /* { dg-warning "zero as null pointer constant" } */ |
| 54 |
1 ? NULL : 0; /* { dg-warning "zero as null pointer constant" } */ |
| 55 |
|
| 56 |
0 ? 0 : 1; |
| 57 |
(void*)0 ? 0 : 1; |
| 58 |
NULL ? 0 : 1; |
| 59 |
nullptr ? 0 : 1; |
| 60 |
|
| 61 |
if (0 == 0); |
| 62 |
if (i == 0); |
| 63 |
if (p == 0); /* { dg-warning "zero as null pointer constant" } */ |
| 64 |
if (0 == p); /* { dg-warning "zero as null pointer constant" } */ |
| 65 |
if (NULL == 0); /* { dg-warning "zero as null pointer constant" } */ |
| 66 |
if (0 == NULL); /* { dg-warning "zero as null pointer constant" } */ |
| 67 |
if (0 == (void*)0); /* { dg-warning "zero as null pointer constant" } */ |
| 68 |
if (0 == nullptr); /* { dg-warning "zero as null pointer constant" } */ |
| 69 |
if (nullptr == 0); /* { dg-warning "zero as null pointer constant" } */ |
| 70 |
|
| 71 |
if (0 != 0); |
| 72 |
if (i != 0); |
| 73 |
if (p != 0); /* { dg-warning "zero as null pointer constant" } */ |
| 74 |
if (0 != p); /* { dg-warning "zero as null pointer constant" } */ |
| 75 |
if (NULL != 0); /* { dg-warning "zero as null pointer constant" } */ |
| 76 |
if (0 != NULL); /* { dg-warning "zero as null pointer constant" } */ |
| 77 |
if (0 != (void*)0); /* { dg-warning "zero as null pointer constant" } */ |
| 78 |
if (0 != nullptr); /* { dg-warning "zero as null pointer constant" } */ |
| 79 |
if (nullptr != 0); /* { dg-warning "zero as null pointer constant" } */ |
| 80 |
|
| 81 |
if (0); |
| 82 |
if (NULL); |
| 83 |
if ((void*)0); |
| 84 |
if (nullptr); |
| 85 |
if (!0); |
| 86 |
if (!NULL); |
| 87 |
if (!(void*)0); |
| 88 |
if (!nullptr); |
| 89 |
|
| 90 |
if (p); |
| 91 |
p ? 0 : 1; |
| 92 |
if (!p); |
| 93 |
(!p) ? 0 : 1; |
| 94 |
|
| 95 |
int *v; |
| 96 |
if (v); |
| 97 |
v ? 1 : 0; |
| 98 |
if (!v); |
| 99 |
(!v) ? 1 : 0; |
| 100 |
|
| 101 |
bool j = p; |
| 102 |
bool k = (bool)p; |
| 103 |
|
| 104 |
baz(p); |
| 105 |
baz((bool)p); |
| 106 |
} |
| 107 |
|