|
| 1 | +// RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s |
| 2 | +// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s |
| 3 | + |
| 4 | +// Use C99 to verify that __need_ can be used to get types that wouldn't normally be available. |
| 5 | + |
| 6 | +struct astruct { char member; }; |
| 7 | + |
| 8 | +ptrdiff_t p0; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}} |
| 9 | +size_t s0; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}} |
| 10 | +rsize_t r0; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}} |
| 11 | +wchar_t wc0; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}} |
| 12 | +void *v0 = NULL; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}} |
| 13 | +nullptr_t n0; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}} |
| 14 | +static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}} |
| 15 | +max_align_t m0; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}} |
| 16 | +size_t o0 = offsetof(struct astruct, member); // c99-error{{unknown type name 'size_t'}} c99-error{{call to undeclared function 'offsetof'}} c99-error{{expected expression}} c99-error{{use of undeclared identifier 'member'}} \ |
| 17 | + c23-error{{unknown type name 'size_t'}} c23-error{{undeclared identifier 'offsetof'}} c23-error{{expected expression}} c23-error{{use of undeclared identifier 'member'}} |
| 18 | +wint_t wi0; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}} |
| 19 | + |
| 20 | +#define __need_ptrdiff_t |
| 21 | +#include <stddef.h> |
| 22 | + |
| 23 | +ptrdiff_t p1; |
| 24 | +size_t s1; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 25 | +rsize_t r1; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 26 | +wchar_t wc1; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 27 | +void *v1 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}} |
| 28 | +nullptr_t n1; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 29 | +static void f1(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} |
| 30 | +max_align_t m1; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 31 | +size_t o1 = offsetof(struct astruct, member); // c99-error{{unknown type}} c99-error{{expected expression}} c99-error{{undeclared identifier}} \ |
| 32 | + c23-error{{unknown type}} c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}} |
| 33 | +wint_t wi1; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 34 | + |
| 35 | +#define __need_size_t |
| 36 | +#include <stddef.h> |
| 37 | + |
| 38 | +ptrdiff_t p2; |
| 39 | +size_t s2; |
| 40 | +rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 41 | + // [email protected]:*{{'size_t' declared here}} [email protected]:*{{'size_t' declared here}} |
| 42 | +wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 43 | +void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}} |
| 44 | +nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 45 | +static void f2(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} |
| 46 | +max_align_t m2; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 47 | +size_t o2 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \ |
| 48 | + c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}} |
| 49 | +wint_t wi2; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 50 | + |
| 51 | +#define __need_rsize_t |
| 52 | +#include <stddef.h> |
| 53 | + |
| 54 | +ptrdiff_t p3; |
| 55 | +size_t s3; |
| 56 | +rsize_t r3; |
| 57 | +wchar_t wc3; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 58 | +void *v3 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}} |
| 59 | +nullptr_t n3; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 60 | +static void f3(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} |
| 61 | +max_align_t m3; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 62 | +size_t o3 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \ |
| 63 | + c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}} |
| 64 | +wint_t wi3; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 65 | + |
| 66 | +#define __need_wchar_t |
| 67 | +#include <stddef.h> |
| 68 | + |
| 69 | +ptrdiff_t p4; |
| 70 | +size_t s4; |
| 71 | +rsize_t r4; |
| 72 | +wchar_t wc4; |
| 73 | +void *v4 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}} |
| 74 | +nullptr_t n4; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 75 | +static void f4(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} |
| 76 | +max_align_t m4; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 77 | +size_t o4 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \ |
| 78 | + c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}} |
| 79 | +wint_t wi4; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 80 | + |
| 81 | +#define __need_NULL |
| 82 | +#include <stddef.h> |
| 83 | + |
| 84 | +ptrdiff_t p5; |
| 85 | +size_t s5; |
| 86 | +rsize_t r5; |
| 87 | +wchar_t wc5; |
| 88 | +void *v5 = NULL; |
| 89 | +nullptr_t n5; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 90 | +static void f5(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} |
| 91 | +max_align_t m5; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 92 | +size_t o5 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \ |
| 93 | + c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}} |
| 94 | +wint_t wi5; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 95 | + |
| 96 | +// __need_nullptr_t generates an error in <C23 because its definition |
| 97 | +// depends on nullptr. |
| 98 | +#define __need_nullptr_t |
| 99 | +#include <stddef.h> // [email protected]:*{{expected function body}} |
| 100 | + |
| 101 | +ptrdiff_t p6; |
| 102 | +size_t s6; |
| 103 | +rsize_t r6; |
| 104 | +wchar_t wc6; |
| 105 | +void *v6 = NULL; |
| 106 | +nullptr_t n6; // c99-error{{unknown type}} |
| 107 | +static void f6(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} |
| 108 | +max_align_t m6; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 109 | +size_t o6 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \ |
| 110 | + c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}} |
| 111 | +wint_t wi6; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 112 | + |
| 113 | +#define __need_unreachable |
| 114 | +#include <stddef.h> |
| 115 | + |
| 116 | +ptrdiff_t p7; |
| 117 | +size_t s7; |
| 118 | +rsize_t r7; |
| 119 | +wchar_t wc7; |
| 120 | +void *v7 = NULL; |
| 121 | +nullptr_t n7 ; // c99-error{{unknown type}} |
| 122 | +static void f7(void) { unreachable(); } |
| 123 | +max_align_t m7; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 124 | +size_t o7 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \ |
| 125 | + c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}} |
| 126 | +wint_t wi7; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 127 | + |
| 128 | +#define __need_max_align_t |
| 129 | +#include <stddef.h> |
| 130 | + |
| 131 | +ptrdiff_t p8; |
| 132 | +size_t s8; |
| 133 | +rsize_t r8; |
| 134 | +wchar_t wc8; |
| 135 | +void *v8 = NULL; |
| 136 | +nullptr_t n8; // c99-error{{unknown type}} |
| 137 | +static void f8(void) { unreachable(); } |
| 138 | +max_align_t m8; |
| 139 | +size_t o8 = offsetof(struct astruct, member); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \ |
| 140 | + c23-error{{undeclared identifier}} c23-error{{expected expression}} c23-error{{undeclared identifier}} |
| 141 | +wint_t wi8; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 142 | + |
| 143 | +#define __need_offsetof |
| 144 | +#include <stddef.h> |
| 145 | + |
| 146 | +ptrdiff_t p9; |
| 147 | +size_t s9; |
| 148 | +rsize_t r9; |
| 149 | +nullptr_t n9; // c99-error{{unknown type}} |
| 150 | +static void f9(void) { unreachable(); } |
| 151 | +wchar_t wc9; |
| 152 | +void *v9 = NULL; |
| 153 | +max_align_t m9; |
| 154 | +size_t o9 = offsetof(struct astruct, member); |
| 155 | +wint_t wi9; // c99-error{{unknown type}} c23-error{{unknown type}} |
| 156 | + |
| 157 | +#define __need_wint_t |
| 158 | +#include <stddef.h> |
| 159 | + |
| 160 | +ptrdiff_t p10; |
| 161 | +size_t s10; |
| 162 | +rsize_t r10; |
| 163 | +wchar_t wc10; |
| 164 | +void *v10 = NULL; |
| 165 | +nullptr_t n10; // c99-error{{unknown type}} |
| 166 | +static void f10(void) { unreachable(); } |
| 167 | +max_align_t m10; |
| 168 | +size_t o10 = offsetof(struct astruct, member); |
| 169 | +wint_t wi10; |
0 commit comments