1 // RUN: %clang_cc1 -std=c++98 -fcxx-exceptions -verify %s
2 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -verify %s
3 // RUN: %clang_cc1 -std=c++14 -fcxx-exceptions -fsized-deallocation -verify %s
4 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -verify %s
5 // RUN: %clang_cc1 -std=c++20 -fcxx-exceptions -fsized-deallocation -verify %s
6 // RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -fsized-deallocation -verify %s
7 //
8 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -frelaxed-template-template-args -DRELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s
9 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -DCONCEPTS_TS=1 -verify %s
10 // RUN: %clang_cc1 -std=c++14 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation
11 // RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -DNO_EXCEPTIONS -DCOROUTINES -verify -fsized-deallocation %s
12 // RUN: %clang_cc1 -std=c++14 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify -fsized-deallocation %s
13 // RUN: %clang_cc1 -std=c++2a -fno-char8_t -DNO_EXCEPTIONS -DNO_CHAR8_T -verify -fsized-deallocation %s
14 
15 // expected-no-diagnostics
16 
17 // FIXME using `defined` in a macro has undefined behavior.
18 #if __cplusplus < 201103L
19 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98)
20 #elif __cplusplus < 201402L
21 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11)
22 #elif __cplusplus < 201703L
23 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14)
24 #elif __cplusplus < 202002L
25 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx17 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx17)
26 #elif __cplusplus == 202002L
27 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx20 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx20)
28 #else
29 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23) (cxx23 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx23)
30 #endif
31 
32 // --- C++2b features ---
33 
34 #if check(size_t_suffix, 0, 0, 0, 0, 0, 202011)
35 #error "wrong value for __cpp_size_t_suffix"
36 #endif
37 
38 // --- C++20 features ---
39 
40 #if check(aggregate_paren_init, 0, 0, 0, 0, 0, 0)
41 // FIXME: 201902 in C++20
42 #error "wrong value for __cpp_aggregate_paren_init"
43 #endif
44 
45 #if defined(CHAR8_T) ? check(char8_t, 201811, 201811, 201811, 201811, 201811, 201811) : \
46     defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0, 0) : \
47     check(char8_t, 0, 0, 0, 0, 201811, 201811)
48 #error "wrong value for __cpp_char8_t"
49 #endif
50 
51 #if check(concepts, 0, 0, 0, 0, 201907, 201907)
52 #error "wrong value for __cpp_concepts"
53 #endif
54 
55 #if check(conditional_explicit, 0, 0, 0, 0, 201806, 201806)
56 #error "wrong value for __cpp_conditional_explicit"
57 #endif
58 
59 #if check(consteval, 0, 0, 0, 0, 0, 0)
60 // FIXME: 201811 in C++20
61 #error "wrong value for __cpp_consteval"
62 #endif
63 
64 // constexpr checked below
65 
66 #if check(constexpr_dynamic_alloc, 0, 0, 0, 0, 201907, 201907)
67 #error "wrong value for __cpp_constexpr_dynamic_alloc"
68 #endif
69 
70 #if check(constexpr_in_decltype, 0, 201711, 201711, 201711, 201711, 201711)
71 #error "wrong value for __cpp_constexpr_in_decltype"
72 #endif
73 
74 #if check(constinit, 0, 0, 0, 0, 201907, 201907)
75 #error "wrong value for __cpp_constinit"
76 #endif
77 
78 // deduction_guides checked below
79 
80 #if check(designated_initializers, 0, 0, 0, 0, 201707, 201707)
81 #error "wrong value for __cpp_designated_initializers"
82 #endif
83 
84 // generic_lambdas checked below
85 
86 #if check(impl_destroying_delete, 201806, 201806, 201806, 201806, 201806, 201806)
87 #error "wrong value for __cpp_impl_destroying_delete"
88 #endif
89 
90 #if check(impl_three_way_comparison, 0, 0, 0, 0, 201907, 201907)
91 #error "wrong value for __cpp_impl_three_way_comparison"
92 #endif
93 
94 // init_captures checked below
95 
96 #if check(modules, 0, 0, 0, 0, 0, 0)
97 // FIXME: 201907 in C++20
98 #error "wrong value for __cpp_modules"
99 #endif
100 
101 #if check(using_enum, 0, 0, 0, 0, 0, 0)
102 // FIXME: 201907 in C++20
103 #error "wrong value for __cpp_using_enum"
104 #endif
105 
106 // --- C++17 features ---
107 
108 #if check(hex_float, 0, 0, 0, 201603, 201603, 201603)
109 #error "wrong value for __cpp_hex_float"
110 #endif
111 
112 #if check(inline_variables, 0, 0, 0, 201606, 201606, 201606)
113 #error "wrong value for __cpp_inline_variables"
114 #endif
115 
116 #if check(aligned_new, 0, 0, 0, 201606, 201606, 201606)
117 #error "wrong value for __cpp_aligned_new"
118 #endif
119 
120 #if check(guaranteed_copy_elision, 0, 0, 0, 201606, 201606, 201606)
121 #error "wrong value for __cpp_guaranteed_copy_elision"
122 #endif
123 
124 #if check(noexcept_function_type, 0, 0, 0, 201510, 201510, 201510)
125 #error "wrong value for __cpp_noexcept_function_type"
126 #endif
127 
128 #if check(fold_expressions, 0, 0, 0, 201603, 201603, 201603)
129 #error "wrong value for __cpp_fold_expressions"
130 #endif
131 
132 #if check(capture_star_this, 0, 0, 0, 201603, 201603, 201603)
133 #error "wrong value for __cpp_capture_star_this"
134 #endif
135 
136 // constexpr checked below
137 
138 #if check(if_constexpr, 0, 0, 0, 201606, 201606, 201606)
139 #error "wrong value for __cpp_if_constexpr"
140 #endif
141 
142 // range_based_for checked below
143 
144 // static_assert checked below
145 
146 #if check(deduction_guides, 0, 0, 0, 201703, 201703, 201703)
147 // FIXME: 201907 in C++20
148 #error "wrong value for __cpp_deduction_guides"
149 #endif
150 
151 #if check(nontype_template_parameter_auto, 0, 0, 0, 201606, 201606, 201606)
152 #error "wrong value for __cpp_nontype_template_parameter_auto"
153 #endif
154 
155 // This is the old name (from P0096R4) for
156 // __cpp_nontype_template_parameter_auto
157 #if check(template_auto, 0, 0, 0, 201606, 201606, 201606)
158 #error "wrong value for __cpp_template_auto"
159 #endif
160 
161 #if check(namespace_attributes, 0, 0, 0, 201411, 201411, 201411)
162 // FIXME: allowed without warning in C++14 and C++11
163 #error "wrong value for __cpp_namespace_attributes"
164 #endif
165 
166 #if check(enumerator_attributes, 0, 0, 0, 201411, 201411, 201411)
167 // FIXME: allowed without warning in C++14 and C++11
168 #error "wrong value for __cpp_enumerator_attributes"
169 #endif
170 
171 // This is an old name (from P0096R4), now removed from SD-6.
172 #if check(nested_namespace_definitions, 0, 0, 0, 201411, 201411, 201411)
173 #error "wrong value for __cpp_nested_namespace_definitions"
174 #endif
175 
176 // inheriting_constructors checked below
177 
178 #if check(variadic_using, 0, 0, 0, 201611, 201611, 201611)
179 #error "wrong value for __cpp_variadic_using"
180 #endif
181 
182 #if check(aggregate_bases, 0, 0, 0, 201603, 201603, 201603)
183 #error "wrong value for __cpp_aggregate_bases"
184 #endif
185 
186 #if check(structured_bindings, 0, 0, 0, 201606, 201606, 201606)
187 #error "wrong value for __cpp_structured_bindings"
188 #endif
189 
190 #if check(nontype_template_args, 0, 0, 0, 201411, 201411, 201411)
191 // FIXME: 201911 in C++20
192 #error "wrong value for __cpp_nontype_template_args"
193 #endif
194 
195 #if defined(RELAXED_TEMPLATE_TEMPLATE_ARGS) \
196     ? check(template_template_args, 0, 0, 0, 201611, 201611, 201611) \
197     : check(template_template_args, 0, 0, 0, 0, 0, 0)
198 #error "wrong value for __cpp_template_template_args"
199 #endif
200 
201 // --- C++14 features ---
202 
203 #if check(binary_literals, 0, 0, 201304, 201304, 201304, 201304)
204 #error "wrong value for __cpp_binary_literals"
205 #endif
206 
207 // (Removed from SD-6.)
208 #if check(digit_separators, 0, 0, 201309, 201309, 201309, 201309)
209 #error "wrong value for __cpp_digit_separators"
210 #endif
211 
212 #if check(init_captures, 0, 0, 201304, 201304, 201803, 201803)
213 #error "wrong value for __cpp_init_captures"
214 #endif
215 
216 #if check(generic_lambdas, 0, 0, 201304, 201304, 201707, 201707)
217 #error "wrong value for __cpp_generic_lambdas"
218 #endif
219 
220 #if check(sized_deallocation, 0, 0, 201309, 201309, 201309, 201309)
221 #error "wrong value for __cpp_sized_deallocation"
222 #endif
223 
224 // constexpr checked below
225 
226 #if check(decltype_auto, 0, 0, 201304, 201304, 201304, 201304)
227 #error "wrong value for __cpp_decltype_auto"
228 #endif
229 
230 #if check(return_type_deduction, 0, 0, 201304, 201304, 201304, 201304)
231 #error "wrong value for __cpp_return_type_deduction"
232 #endif
233 
234 #if check(runtime_arrays, 0, 0, 0, 0, 0, 0)
235 #error "wrong value for __cpp_runtime_arrays"
236 #endif
237 
238 #if check(aggregate_nsdmi, 0, 0, 201304, 201304, 201304, 201304)
239 #error "wrong value for __cpp_aggregate_nsdmi"
240 #endif
241 
242 #if check(variable_templates, 0, 0, 201304, 201304, 201304, 201304)
243 #error "wrong value for __cpp_variable_templates"
244 #endif
245 
246 // --- C++11 features ---
247 
248 #if check(unicode_characters, 0, 200704, 200704, 200704, 200704, 200704)
249 #error "wrong value for __cpp_unicode_characters"
250 #endif
251 
252 #if check(raw_strings, 0, 200710, 200710, 200710, 200710, 200710)
253 #error "wrong value for __cpp_raw_strings"
254 #endif
255 
256 #if check(unicode_literals, 0, 200710, 200710, 200710, 200710, 200710)
257 #error "wrong value for __cpp_unicode_literals"
258 #endif
259 
260 #if check(user_defined_literals, 0, 200809, 200809, 200809, 200809, 200809)
261 #error "wrong value for __cpp_user_defined_literals"
262 #endif
263 
264 #if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0, 0, 0) : \
265                                      check(threadsafe_static_init, 200806, 200806, 200806, 200806, 200806, 200806)
266 #error "wrong value for __cpp_threadsafe_static_init"
267 #endif
268 
269 #if check(lambdas, 0, 200907, 200907, 200907, 200907, 200907)
270 #error "wrong value for __cpp_lambdas"
271 #endif
272 
273 #if check(constexpr, 0, 200704, 201304, 201603, 201907, 201907)
274 #error "wrong value for __cpp_constexpr"
275 #endif
276 
277 #if check(range_based_for, 0, 200907, 200907, 201603, 201603, 201603)
278 #error "wrong value for __cpp_range_based_for"
279 #endif
280 
281 #if check(static_assert, 0, 200410, 200410, 201411, 201411, 201411)
282 #error "wrong value for __cpp_static_assert"
283 #endif
284 
285 #if check(decltype, 0, 200707, 200707, 200707, 200707, 200707)
286 #error "wrong value for __cpp_decltype"
287 #endif
288 
289 #if check(attributes, 0, 200809, 200809, 200809, 200809, 200809)
290 #error "wrong value for __cpp_attributes"
291 #endif
292 
293 #if check(rvalue_references, 0, 200610, 200610, 200610, 200610, 200610)
294 #error "wrong value for __cpp_rvalue_references"
295 #endif
296 
297 #if check(variadic_templates, 0, 200704, 200704, 200704, 200704, 200704)
298 #error "wrong value for __cpp_variadic_templates"
299 #endif
300 
301 #if check(initializer_lists, 0, 200806, 200806, 200806, 200806, 200806)
302 #error "wrong value for __cpp_initializer_lists"
303 #endif
304 
305 #if check(delegating_constructors, 0, 200604, 200604, 200604, 200604, 200604)
306 #error "wrong value for __cpp_delegating_constructors"
307 #endif
308 
309 #if check(nsdmi, 0, 200809, 200809, 200809, 200809, 200809)
310 #error "wrong value for __cpp_nsdmi"
311 #endif
312 
313 #if check(inheriting_constructors, 0, 201511, 201511, 201511, 201511, 201511)
314 #error "wrong value for __cpp_inheriting_constructors"
315 #endif
316 
317 #if check(ref_qualifiers, 0, 200710, 200710, 200710, 200710, 200710)
318 #error "wrong value for __cpp_ref_qualifiers"
319 #endif
320 
321 #if check(alias_templates, 0, 200704, 200704, 200704, 200704, 200704)
322 #error "wrong value for __cpp_alias_templates"
323 #endif
324 
325 // --- C++98 features ---
326 
327 #if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0, 0, 0) : check(rtti, 199711, 199711, 199711, 199711, 199711, 199711)
328 #error "wrong value for __cpp_rtti"
329 #endif
330 
331 #if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0, 0, 0) : check(exceptions, 199711, 199711, 199711, 199711, 199711, 199711)
332 #error "wrong value for __cpp_exceptions"
333 #endif
334 
335 // --- TS features --
336 
337 #if defined(COROUTINES) ? check(coroutines, 201703, 201703, 201703, 201703, 201703, 201703) : check(coroutines, 0, 0, 0, 0, 201703, 201703)
338 #error "wrong value for __cpp_coroutines"
339 #endif
340