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