Debian Codegraph @

clang/test/Lexer/cxx-features.cpp

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