2 // RUN: %clang_cc1 -fsyntax-only -verify=c99 -std=c99 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 %s
4 // RUN: %clang_cc1 -fsyntax-only -verify=c99-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c99 %s
5 // RUN: %clang_cc1 -fsyntax-only -verify=c23-modules -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -std=c23 %s
7 // Use C99 to verify that __need_ can be used to get types that wouldn't normally be available.
9 struct astruct
{ char member
; };
11 ptrdiff_t p0
; // c99-error{{unknown type name 'ptrdiff_t'}} c23-error{{unknown type}} \
12 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
13 size_t s0
; // c99-error{{unknown type name 'size_t'}} c23-error{{unknown type}} \
14 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
15 rsize_t r0
; // c99-error{{unknown type name 'rsize_t'}} c23-error{{unknown type}} \
16 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
17 wchar_t wc0
; // c99-error{{unknown type name 'wchar_t'}} c23-error{{unknown type}} \
18 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
19 void *v0
= NULL
; // c99-error{{use of undeclared identifier 'NULL'}} c23-error{{undeclared identifier}} \
20 c99
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{undeclared identifier
}}
21 nullptr_t n0
; // c99-error{{unknown type name 'nullptr_t'}} c23-error{{unknown type}} \
22 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
23 static void f0(void) { unreachable(); } // c99-error{{call to undeclared function 'unreachable'}} c23-error{{undeclared identifier 'unreachable'}} \
24 c99
-modules
-error
{{undeclared function
}} c23
-modules
-error
{{undeclared identifier
}}
25 max_align_t m0
; // c99-error{{unknown type name 'max_align_t'}} c23-error{{unknown type}} \
26 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
27 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'}} \
28 c23
-error
{{unknown type name
'size_t'}} c23
-error
{{undeclared identifier
'offsetof'}} c23
-error
{{expected expression
}} c23
-error
{{use of undeclared identifier
'member'}} \
29 c99
-modules
-error
{{unknown type
}} c99
-modules
-error
{{undeclared function
}} c99
-modules
-error
{{expected expression
}} c99
-modules
-error
{{undeclared identifier
}} \
30 c23
-modules
-error
{{unknown type
}} c23
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{expected expression
}} c23
-modules
-error
{{undeclared identifier
}}
31 wint_t wi0
; // c99-error{{unknown type name 'wint_t'}} c23-error{{unknown type}} \
32 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
34 #define __need_ptrdiff_t
38 size_t s1
; // c99-error{{unknown type}} c23-error{{unknown type}} \
39 c99
-modules
-error
{{'size_t' must be declared before it is used
}} c23
-modules
-error
{{must be declared
}} \
40 c99
-modules
-note@__stddef_size_t
.h
:*{{declaration here is
not visible
}} c23
-modules
-note@__stddef_size_t
.h
:*{{declaration here is
not visible
}}
41 rsize_t r1
; // c99-error{{unknown type}} c23-error{{unknown type}} \
42 c99
-modules
-error
{{'rsize_t' must be declared before it is used
}} c23
-modules
-error
{{must be declared
}} \
43 c99
-modules
-note@__stddef_rsize_t
.h
:*{{declaration here is
not visible
}} c23
-modules
-note@__stddef_rsize_t
.h
:*{{declaration here is
not visible
}}
44 wchar_t wc1
; // c99-error{{unknown type}} c23-error{{unknown type}} \
45 c99
-modules
-error
{{'wchar_t' must be declared before it is used
}} c23
-modules
-error
{{must be declared
}} \
46 c99
-modules
-note@__stddef_wchar_t
.h
:*{{declaration here is
not visible
}} c23
-modules
-note@__stddef_wchar_t
.h
:*{{declaration here is
not visible
}}
47 void *v1
= NULL
; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}} \
48 c99
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{undeclared identifier
}}
49 nullptr_t n1
; // c99-error{{unknown type}} c23-error{{unknown type}} \
50 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{'nullptr_t' must be declared before it is used
}} \
51 c23
-modules
-note@__stddef_nullptr_t
.h
:*{{declaration here is
not visible
}}
52 static void f1(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} \
53 c99
-modules
-error
{{undeclared function
}} c23
-modules
-error
{{undeclared identifier
}}
54 max_align_t m1
; // c99-error{{unknown type}} c23-error{{unknown type}} \
55 c99
-modules
-error
{{'max_align_t' must be declared before it is used
}} c23
-modules
-error
{{must be declared
}} \
56 c99
-modules
-note@__stddef_max_align_t
.h
:*{{declaration here is
not visible
}} c23
-modules
-note@__stddef_max_align_t
.h
:*{{declaration here is
not visible
}}
57 size_t o1
= offsetof(struct astruct
, member
); // c99-error{{unknown type}} c99-error{{expected expression}} c99-error{{undeclared identifier}} \
58 c23
-error
{{unknown type
}} c23
-error
{{undeclared identifier
}} c23
-error
{{expected expression
}} c23
-error
{{undeclared identifier
}} \
59 c99
-modules
-error
{{expected expression
}} c99
-modules
-error
{{undeclared identifier
}} \
60 c23
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{expected expression
}} c23
-modules
-error
{{undeclared identifier
}}
61 wint_t wi1
; // c99-error{{unknown type}} c23-error{{unknown type}} \
62 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
64 // The "must be declared before used" errors are only emitted the first time a
65 // known-but-not-visible type is seen. At this point the _Builtin_stddef module
66 // has been built and all of the types tried, so most of the errors won't be
67 // repeated below in modules. The types still aren't available, just the errors
68 // aren't repeated. e.g. rsize_t still isn't available, if r1 above got deleted,
69 // its error would move to r2 below.
76 rsize_t r2
; // c99-error{{unknown type}} c23-error{{unknown type}}
77 // c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
78 wchar_t wc2
; // c99-error{{unknown type}} c23-error{{unknown type}}
79 void *v2
= NULL
; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}} \
80 c99
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{undeclared identifier
}}
81 nullptr_t n2
; // c99-error{{unknown type}} c23-error{{unknown type}} \
82 c99
-modules
-error
{{unknown type
}}
83 static void f2(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} \
84 c99
-modules
-error
{{undeclared function
}} c23
-modules
-error
{{undeclared identifier
}}
85 max_align_t m2
; // c99-error{{unknown type}} c23-error{{unknown type}}
86 size_t o2
= offsetof(struct astruct
, member
); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
87 c23
-error
{{undeclared identifier
}} c23
-error
{{expected expression
}} c23
-error
{{undeclared identifier
}} \
88 c99
-modules
-error
{{expected expression
}} c99
-modules
-error
{{undeclared identifier
}} \
89 c23
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{expected expression
}} c23
-modules
-error
{{undeclared identifier
}}
90 wint_t wi2
; // c99-error{{unknown type}} c23-error{{unknown type}} \
91 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
93 #define __need_rsize_t
99 wchar_t wc3
; // c99-error{{unknown type}} c23-error{{unknown type}}
100 void *v3
= NULL
; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}} \
101 c99
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{undeclared identifier
}}
102 nullptr_t n3
; // c99-error{{unknown type}} c23-error{{unknown type}} \
103 c99
-modules
-error
{{unknown type
}}
104 static void f3(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} \
105 c99
-modules
-error
{{undeclared function
}} c23
-modules
-error
{{undeclared identifier
}}
106 max_align_t m3
; // c99-error{{unknown type}} c23-error{{unknown type}}
107 size_t o3
= offsetof(struct astruct
, member
); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
108 c23
-error
{{undeclared identifier
}} c23
-error
{{expected expression
}} c23
-error
{{undeclared identifier
}} \
109 c99
-modules
-error
{{expected expression
}} c99
-modules
-error
{{undeclared identifier
}} \
110 c23
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{expected expression
}} c23
-modules
-error
{{undeclared identifier
}}
111 wint_t wi3
; // c99-error{{unknown type}} c23-error{{unknown type}} \
112 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
114 #define __need_wchar_t
121 void *v4
= NULL
; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}} \
122 c99
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{undeclared identifier
}}
123 nullptr_t n4
; // c99-error{{unknown type}} c23-error{{unknown type}} \
124 c99
-modules
-error
{{unknown type
}}
125 static void f4(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} \
126 c99
-modules
-error
{{undeclared function
}} c23
-modules
-error
{{undeclared identifier
}}
127 max_align_t m4
; // c99-error{{unknown type}} c23-error{{unknown type}}
128 size_t o4
= offsetof(struct astruct
, member
); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
129 c23
-error
{{undeclared identifier
}} c23
-error
{{expected expression
}} c23
-error
{{undeclared identifier
}} \
130 c99
-modules
-error
{{expected expression
}} c99
-modules
-error
{{undeclared identifier
}} \
131 c23
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{expected expression
}} c23
-modules
-error
{{undeclared identifier
}}
132 wint_t wi4
; // c99-error{{unknown type}} c23-error{{unknown type}} \
133 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
143 nullptr_t n5
; // c99-error{{unknown type}} c23-error{{unknown type}} \
144 c99
-modules
-error
{{unknown type
}}
145 static void f5(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} \
146 c99
-modules
-error
{{undeclared function
}} c23
-modules
-error
{{undeclared identifier
}}
147 max_align_t m5
; // c99-error{{unknown type}} c23-error{{unknown type}}
148 size_t o5
= offsetof(struct astruct
, member
); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
149 c23
-error
{{undeclared identifier
}} c23
-error
{{expected expression
}} c23
-error
{{undeclared identifier
}} \
150 c99
-modules
-error
{{expected expression
}} c99
-modules
-error
{{undeclared identifier
}} \
151 c23
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{expected expression
}} c23
-modules
-error
{{undeclared identifier
}}
152 wint_t wi5
; // c99-error{{unknown type}} c23-error{{unknown type}} \
153 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
155 // nullptr_t doesn't get declared before C23 because its definition
156 // depends on nullptr.
157 #define __need_nullptr_t
165 nullptr_t n6
; // c99-error{{unknown type}} c99-modules-error{{unknown type}}
166 static void f6(void) { unreachable(); } // c99-error{{undeclared function}} c23-error{{undeclared identifier}} \
167 c99
-modules
-error
{{undeclared function
}} c23
-modules
-error
{{undeclared identifier
}}
168 max_align_t m6
; // c99-error{{unknown type}} c23-error{{unknown type}}
169 size_t o6
= offsetof(struct astruct
, member
); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
170 c23
-error
{{undeclared identifier
}} c23
-error
{{expected expression
}} c23
-error
{{undeclared identifier
}} \
171 c99
-modules
-error
{{expected expression
}} c99
-modules
-error
{{undeclared identifier
}} \
172 c23
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{expected expression
}} c23
-modules
-error
{{undeclared identifier
}}
173 wint_t wi6
; // c99-error{{unknown type}} c23-error{{unknown type}} \
174 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
176 #define __need_unreachable
184 nullptr_t n7
; // c99-error{{unknown type}} c99-modules-error{{unknown type}}
185 static void f7(void) { unreachable(); }
186 max_align_t m7
; // c99-error{{unknown type}} c23-error{{unknown type}}
187 size_t o7
= offsetof(struct astruct
, member
); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
188 c23
-error
{{undeclared identifier
}} c23
-error
{{expected expression
}} c23
-error
{{undeclared identifier
}} \
189 c99
-modules
-error
{{expected expression
}} c99
-modules
-error
{{undeclared identifier
}} \
190 c23
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{expected expression
}} c23
-modules
-error
{{undeclared identifier
}}
191 wint_t wi7
; // c99-error{{unknown type}} c23-error{{unknown type}} \
192 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
194 #define __need_max_align_t
202 nullptr_t n8
; // c99-error{{unknown type}} c99-modules-error{{unknown type}}
203 static void f8(void) { unreachable(); }
205 size_t o8
= offsetof(struct astruct
, member
); // c99-error{{expected expression}} c99-error{{undeclared identifier}} \
206 c23
-error
{{undeclared identifier
}} c23
-error
{{expected expression
}} c23
-error
{{undeclared identifier
}} \
207 c99
-modules
-error
{{expected expression
}} c99
-modules
-error
{{undeclared identifier
}} \
208 c23
-modules
-error
{{undeclared identifier
}} c23
-modules
-error
{{expected expression
}} c23
-modules
-error
{{undeclared identifier
}}
209 wint_t wi8
; // c99-error{{unknown type}} c23-error{{unknown type}} \
210 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
212 #define __need_offsetof
218 nullptr_t n9
; // c99-error{{unknown type}} c99-modules-error{{unknown type}}
219 static void f9(void) { unreachable(); }
223 size_t o9
= offsetof(struct astruct
, member
);
224 wint_t wi9
; // c99-error{{unknown type}} c23-error{{unknown type}} \
225 c99
-modules
-error
{{unknown type
}} c23
-modules
-error
{{unknown type
}}
227 #define __need_wint_t
235 nullptr_t n10
; // c99-error{{unknown type}} c99-modules-error{{unknown type}}
236 static void f10(void) { unreachable(); }
238 size_t o10
= offsetof(struct astruct
, member
);