[mlir][ods] Store the pointer to the anchor element (NFC)
[llvm-project.git] / libcxx / utils / generate_feature_test_macro_components.py
blob37860a731d2996b5187700827f74fc7dd626245f
1 #!/usr/bin/env python
3 import os
4 from builtins import range
5 from functools import reduce
7 def get_libcxx_paths():
8 utils_path = os.path.dirname(os.path.abspath(__file__))
9 script_name = os.path.basename(__file__)
10 assert os.path.exists(utils_path)
11 src_root = os.path.dirname(utils_path)
12 include_path = os.path.join(src_root, 'include')
13 assert os.path.exists(include_path)
14 docs_path = os.path.join(src_root, 'docs')
15 assert os.path.exists(docs_path)
16 macro_test_path = os.path.join(src_root, 'test', 'std', 'language.support',
17 'support.limits', 'support.limits.general')
18 assert os.path.exists(macro_test_path)
19 assert os.path.exists(os.path.join(macro_test_path, 'version.version.compile.pass.cpp'))
20 return script_name, src_root, include_path, docs_path, macro_test_path
22 script_name, source_root, include_path, docs_path, macro_test_path = get_libcxx_paths()
24 def has_header(h):
25 h_path = os.path.join(include_path, h)
26 return os.path.exists(h_path)
28 def add_version_header(tc):
29 tc["headers"].append("version")
30 return tc
32 # ================ ============================================================
33 # Field Description
34 # ================ ============================================================
35 # name The name of the feature-test macro.
36 # values A dict whose keys are C++ versions and whose values are the
37 # value of the feature-test macro for that C++ version.
38 # (TODO: This isn't a very clean model for feature-test
39 # macros affected by multiple papers.)
40 # headers An array with the headers that should provide the
41 # feature-test macro.
42 # test_suite_guard An optional string field. When this field is provided,
43 # `libcxx_guard` must also be provided. This field is used
44 # only to generate the unit tests for the feature-test macros.
45 # It can't depend on macros defined in <__config> because the
46 # `test/std/` parts of the test suite are intended to be
47 # portable to any C++ standard library implementation, not
48 # just libc++. It may depend on
49 # * macros defined by the compiler itself, or
50 # * macros generated by CMake.
51 # In some cases we add
52 # `&& !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM_...)`
53 # in order to make libc++ pass the tests on OSX; see D94983.
54 # libcxx_guard An optional string field. When this field is provided,
55 # `test_suite_guard` must also be provided. This field is used
56 # only to guard the feature-test macro in <version>. It may
57 # be the same as `test_suite_guard`, or it may depend on
58 # macros defined in <__config>.
59 # unimplemented An optional Boolean field with the value `True`. This field
60 # is only used when a feature isn't fully implemented. Once
61 # you've fully implemented the feature, you should remove
62 # this field.
63 # ================ ============================================================
64 feature_test_macros = [ add_version_header(x) for x in [
66 "name": "__cpp_lib_adaptor_iterator_pair_constructor",
67 "values": { "c++2b": 202106 },
68 "headers": ["queue", "stack"],
69 }, {
70 "name": "__cpp_lib_addressof_constexpr",
71 "values": { "c++17": 201603 },
72 "headers": ["memory"],
73 }, {
74 "name": "__cpp_lib_allocate_at_least",
75 "values": { "c++2b": 202106 },
76 "headers": ["memory"],
77 }, {
78 "name": "__cpp_lib_allocator_traits_is_always_equal",
79 "values": { "c++17": 201411 },
80 "headers": ["deque", "forward_list", "list", "map", "memory", "scoped_allocator", "set", "string", "unordered_map", "unordered_set", "vector"],
81 }, {
82 "name": "__cpp_lib_any",
83 "values": { "c++17": 201606 },
84 "headers": ["any"],
85 }, {
86 "name": "__cpp_lib_apply",
87 "values": { "c++17": 201603 },
88 "headers": ["tuple"],
89 }, {
90 "name": "__cpp_lib_array_constexpr",
91 "values": { "c++17": 201603, "c++20": 201811 },
92 "headers": ["array", "iterator"],
93 }, {
94 "name": "__cpp_lib_as_const",
95 "values": { "c++17": 201510 },
96 "headers": ["utility"],
97 }, {
98 "name": "__cpp_lib_associative_heterogeneous_erasure",
99 "values": { "c++2b": 202110 },
100 "headers": ["map", "set", "unordered_map", "unordered_set"],
101 "unimplemented": True,
102 }, {
103 "name": "__cpp_lib_assume_aligned",
104 "values": { "c++20": 201811 },
105 "headers": ["memory"],
106 }, {
107 "name": "__cpp_lib_atomic_flag_test",
108 "values": { "c++20": 201907 },
109 "headers": ["atomic"],
110 }, {
111 "name": "__cpp_lib_atomic_float",
112 "values": { "c++20": 201711 },
113 "headers": ["atomic"],
114 "unimplemented": True,
115 }, {
116 "name": "__cpp_lib_atomic_is_always_lock_free",
117 "values": { "c++17": 201603 },
118 "headers": ["atomic"],
119 }, {
120 "name": "__cpp_lib_atomic_lock_free_type_aliases",
121 "values": { "c++20": 201907 },
122 "headers": ["atomic"],
123 }, {
124 "name": "__cpp_lib_atomic_ref",
125 "values": { "c++20": 201806 },
126 "headers": ["atomic"],
127 "unimplemented": True,
128 }, {
129 "name": "__cpp_lib_atomic_shared_ptr",
130 "values": { "c++20": 201711 },
131 "headers": ["atomic"],
132 "unimplemented": True,
133 }, {
134 "name": "__cpp_lib_atomic_value_initialization",
135 "values": { "c++20": 201911 },
136 "headers": ["atomic", "memory"],
137 }, {
138 "name": "__cpp_lib_atomic_wait",
139 "values": { "c++20": 201907 },
140 "headers": ["atomic"],
141 "test_suite_guard": "!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)",
142 "libcxx_guard": "!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_atomic_wait)",
143 }, {
144 "name": "__cpp_lib_barrier",
145 "values": { "c++20": 201907 },
146 "headers": ["barrier"],
147 "test_suite_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier)",
148 "libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier)",
149 }, {
150 "name": "__cpp_lib_bind_back",
151 "values": { "c++2b": 202202 },
152 "headers": ["functional"],
153 "unimplemented": True,
154 }, {
155 "name": "__cpp_lib_bind_front",
156 "values": { "c++20": 201907 },
157 "headers": ["functional"],
158 }, {
159 "name": "__cpp_lib_bit_cast",
160 "values": { "c++20": 201806 },
161 "headers": ["bit"],
162 }, {
163 "name": "__cpp_lib_bitops",
164 "values": { "c++20": 201907 },
165 "headers": ["bit"],
166 "unimplemented": True,
167 }, {
168 "name": "__cpp_lib_bool_constant",
169 "values": { "c++17": 201505 },
170 "headers": ["type_traits"],
171 }, {
172 "name": "__cpp_lib_bounded_array_traits",
173 "values": { "c++20": 201902 },
174 "headers": ["type_traits"],
175 }, {
176 "name": "__cpp_lib_boyer_moore_searcher",
177 "values": { "c++17": 201603 },
178 "headers": ["functional"],
179 }, {
180 "name": "__cpp_lib_byte",
181 "values": { "c++17": 201603 },
182 "headers": ["cstddef"],
183 }, {
184 "name": "__cpp_lib_byteswap",
185 "values": { "c++2b": 202110 },
186 "headers": ["bit"],
187 }, {
188 "name": "__cpp_lib_char8_t",
189 "values": { "c++20": 201907 },
190 "headers": ["atomic", "filesystem", "istream", "limits", "locale", "ostream", "string", "string_view"],
191 "test_suite_guard": "defined(__cpp_char8_t)",
192 "libcxx_guard": "!defined(_LIBCPP_HAS_NO_CHAR8_T)",
193 }, {
194 "name": "__cpp_lib_chrono",
195 "values": { "c++17": 201611 },
196 "headers": ["chrono"],
197 }, {
198 "name": "__cpp_lib_chrono_udls",
199 "values": { "c++14": 201304 },
200 "headers": ["chrono"],
201 }, {
202 "name": "__cpp_lib_clamp",
203 "values": { "c++17": 201603 },
204 "headers": ["algorithm"],
205 }, {
206 "name": "__cpp_lib_complex_udls",
207 "values": { "c++14": 201309 },
208 "headers": ["complex"],
209 }, {
210 "name": "__cpp_lib_concepts",
211 "values": { "c++20": 202002 },
212 "headers": ["concepts"],
213 }, {
214 "name": "__cpp_lib_constexpr_algorithms",
215 "values": { "c++20": 201806 },
216 "headers": ["algorithm"],
217 }, {
218 "name": "__cpp_lib_constexpr_bitset",
219 "values": { "c++2b": 202207 },
220 "headers": ["bitset"],
221 }, {
222 "name": "__cpp_lib_constexpr_cmath",
223 "values": { "c++2b": 202202 },
224 "headers": ["cmath", "cstdlib"],
225 "unimplemented": True,
226 }, {
227 "name": "__cpp_lib_constexpr_complex",
228 "values": { "c++20": 201711 },
229 "headers": ["complex"],
230 "unimplemented": True,
231 }, {
232 "name": "__cpp_lib_constexpr_dynamic_alloc",
233 "values": { "c++20": 201907 },
234 "headers": ["memory"],
235 }, {
236 "name": "__cpp_lib_constexpr_functional",
237 "values": { "c++20": 201907 },
238 "headers": ["functional"],
239 }, {
240 "name": "__cpp_lib_constexpr_iterator",
241 "values": { "c++20": 201811 },
242 "headers": ["iterator"],
243 }, {
244 "name": "__cpp_lib_constexpr_memory",
245 "values": { "c++20": 201811, "c++2b": 202202 },
246 "headers": ["memory"],
247 }, {
248 "name": "__cpp_lib_constexpr_numeric",
249 "values": { "c++20": 201911 },
250 "headers": ["numeric"],
251 }, {
252 "name": "__cpp_lib_constexpr_string",
253 "values": { "c++20": 201907 },
254 "headers": ["string"],
255 }, {
256 "name": "__cpp_lib_constexpr_string_view",
257 "values": { "c++20": 201811 },
258 "headers": ["string_view"],
259 }, {
260 "name": "__cpp_lib_constexpr_tuple",
261 "values": { "c++20": 201811 },
262 "headers": ["tuple"],
263 }, {
264 "name": "__cpp_lib_constexpr_typeinfo",
265 "values": { "c++2b": 202106 },
266 "headers": ["typeinfo"],
267 "unimplemented": True,
268 }, {
269 "name": "__cpp_lib_constexpr_utility",
270 "values": { "c++20": 201811 },
271 "headers": ["utility"],
272 }, {
273 "name": "__cpp_lib_constexpr_vector",
274 "values": { "c++20": 201907 },
275 "headers": ["vector"],
276 "unimplemented": True,
277 }, {
278 "name": "__cpp_lib_coroutine",
279 "values": { "c++20": 201902 },
280 "headers": ["coroutine"],
281 }, {
282 "name": "__cpp_lib_destroying_delete",
283 "values": { "c++20": 201806 },
284 "headers": ["new"],
285 "test_suite_guard": "TEST_STD_VER > 17 && defined(__cpp_impl_destroying_delete) && __cpp_impl_destroying_delete >= 201806L",
286 "libcxx_guard": "_LIBCPP_STD_VER > 17 && defined(__cpp_impl_destroying_delete) && __cpp_impl_destroying_delete >= 201806L",
287 }, {
288 "name": "__cpp_lib_enable_shared_from_this",
289 "values": { "c++17": 201603 },
290 "headers": ["memory"],
291 }, {
292 "name": "__cpp_lib_endian",
293 "values": { "c++20": 201907 },
294 "headers": ["bit"],
295 }, {
296 "name": "__cpp_lib_erase_if",
297 "values": { "c++20": 202002 },
298 "headers": ["deque", "forward_list", "list", "map", "set", "string", "unordered_map", "unordered_set", "vector"],
299 }, {
300 "name": "__cpp_lib_exchange_function",
301 "values": { "c++14": 201304 },
302 "headers": ["utility"],
303 }, {
304 "name": "__cpp_lib_execution",
305 "values": { "c++17": 201603, "c++20": 201902 },
306 "headers": ["execution"],
307 "unimplemented": True,
308 }, {
309 "name": "__cpp_lib_filesystem",
310 "values": { "c++17": 201703 },
311 "headers": ["filesystem"],
312 "test_suite_guard": "!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem)",
313 "libcxx_guard": "!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_filesystem)"
314 }, {
315 "name": "__cpp_lib_format",
316 "values": {
317 # "c++20": 201907 Not implemented P1361R2 Integration of chrono with text formatting
318 # "c++20": 202106 Fully implemented
319 # "c++20": 202110 Not implemented P2372R3 Fixing locale handling in chrono formatters
320 "c++20": 202106,
321 # "c++23": 202207, Not implemented P2419R2 Clarify handling of encodings in localized formatting of chrono types
323 "headers": ["format"],
324 "test_suite_guard": "!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)",
325 "libcxx_guard": "!defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_format) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)",
326 "unimplemented": True,
327 }, {
328 "name": "__cpp_lib_forward_like",
329 "values": { "c++2b": 202207 },
330 "headers": ["utility"],
331 }, {
332 "name": "__cpp_lib_gcd_lcm",
333 "values": { "c++17": 201606 },
334 "headers": ["numeric"],
335 }, {
336 "name": "__cpp_lib_generic_associative_lookup",
337 "values": { "c++14": 201304 },
338 "headers": ["map", "set"],
339 }, {
340 "name": "__cpp_lib_generic_unordered_lookup",
341 "values": { "c++20": 201811 },
342 "headers": ["unordered_map", "unordered_set"],
343 }, {
344 "name": "__cpp_lib_hardware_interference_size",
345 "values": { "c++17": 201703 },
346 "test_suite_guard": "defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)",
347 "libcxx_guard": "defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)",
348 "headers": ["new"],
349 }, {
350 "name": "__cpp_lib_has_unique_object_representations",
351 "values": { "c++17": 201606 },
352 "headers": ["type_traits"],
353 }, {
354 "name": "__cpp_lib_hypot",
355 "values": { "c++17": 201603 },
356 "headers": ["cmath"],
357 }, {
358 "name": "__cpp_lib_incomplete_container_elements",
359 "values": { "c++17": 201505 },
360 "headers": ["forward_list", "list", "vector"],
361 }, {
362 "name": "__cpp_lib_int_pow2",
363 "values": { "c++20": 202002 },
364 "headers": ["bit"],
365 }, {
366 "name": "__cpp_lib_integer_comparison_functions",
367 "values": { "c++20": 202002 },
368 "headers": ["utility"],
369 }, {
370 "name": "__cpp_lib_integer_sequence",
371 "values": { "c++14": 201304 },
372 "headers": ["utility"],
373 }, {
374 "name": "__cpp_lib_integral_constant_callable",
375 "values": { "c++14": 201304 },
376 "headers": ["type_traits"],
377 }, {
378 "name": "__cpp_lib_interpolate",
379 "values": { "c++20": 201902 },
380 "headers": ["cmath", "numeric"],
381 }, {
382 "name": "__cpp_lib_invoke",
383 "values": { "c++17": 201411 },
384 "headers": ["functional"],
385 }, {
386 "name": "__cpp_lib_invoke_r",
387 "values": { "c++2b": 202106 },
388 "headers": ["functional"],
389 "unimplemented": True,
390 }, {
391 "name": "__cpp_lib_is_aggregate",
392 "values": { "c++17": 201703 },
393 "headers": ["type_traits"],
394 }, {
395 "name": "__cpp_lib_is_constant_evaluated",
396 "values": { "c++20": 201811 },
397 "headers": ["type_traits"],
398 }, {
399 "name": "__cpp_lib_is_final",
400 "values": { "c++14": 201402 },
401 "headers": ["type_traits"],
402 }, {
403 "name": "__cpp_lib_is_invocable",
404 "values": { "c++17": 201703 },
405 "headers": ["type_traits"],
406 }, {
407 "name": "__cpp_lib_is_layout_compatible",
408 "values": { "c++20": 201907 },
409 "headers": ["type_traits"],
410 "unimplemented": True,
411 }, {
412 "name": "__cpp_lib_is_nothrow_convertible",
413 "values": { "c++20": 201806 },
414 "headers": ["type_traits"],
415 }, {
416 "name": "__cpp_lib_is_null_pointer",
417 "values": { "c++14": 201309 },
418 "headers": ["type_traits"],
419 }, {
420 "name": "__cpp_lib_is_pointer_interconvertible",
421 "values": { "c++20": 201907 },
422 "headers": ["type_traits"],
423 "unimplemented": True,
424 }, {
425 "name": "__cpp_lib_is_scoped_enum",
426 "values": { "c++2b": 202011 },
427 "headers": ["type_traits"],
428 }, {
429 "name": "__cpp_lib_is_swappable",
430 "values": { "c++17": 201603 },
431 "headers": ["type_traits"],
432 }, {
433 "name": "__cpp_lib_jthread",
434 "values": { "c++20": 201911 },
435 "headers": ["stop_token", "thread"],
436 "test_suite_guard": "!defined(_LIBCPP_HAS_NO_THREADS)",
437 "libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS)",
438 "unimplemented": True,
439 }, {
440 "name": "__cpp_lib_latch",
441 "values": { "c++20": 201907 },
442 "headers": ["latch"],
443 "test_suite_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_latch)",
444 "libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_latch)",
445 }, {
446 "name": "__cpp_lib_launder",
447 "values": { "c++17": 201606 },
448 "headers": ["new"],
449 }, {
450 "name": "__cpp_lib_list_remove_return_type",
451 "values": { "c++20": 201806 },
452 "headers": ["forward_list", "list"],
453 }, {
454 "name": "__cpp_lib_logical_traits",
455 "values": { "c++17": 201510 },
456 "headers": ["type_traits"],
457 }, {
458 "name": "__cpp_lib_make_from_tuple",
459 "values": { "c++17": 201606 },
460 "headers": ["tuple"],
461 }, {
462 "name": "__cpp_lib_make_reverse_iterator",
463 "values": { "c++14": 201402 },
464 "headers": ["iterator"],
465 }, {
466 "name": "__cpp_lib_make_unique",
467 "values": { "c++14": 201304 },
468 "headers": ["memory"],
469 }, {
470 "name": "__cpp_lib_map_try_emplace",
471 "values": { "c++17": 201411 },
472 "headers": ["map"],
473 }, {
474 "name": "__cpp_lib_math_constants",
475 "values": { "c++20": 201907 },
476 "headers": ["numbers"],
477 }, {
478 "name": "__cpp_lib_math_special_functions",
479 "values": { "c++17": 201603 },
480 "headers": ["cmath"],
481 "unimplemented": True,
482 }, {
483 "name": "__cpp_lib_memory_resource",
484 "values": { "c++17": 201603 },
485 "headers": ["memory_resource"],
486 "unimplemented": True,
487 }, {
488 "name": "__cpp_lib_move_only_function",
489 "values": { "c++2b": 202110 },
490 "headers": ["functional"],
491 "unimplemented": True,
492 }, {
493 "name": "__cpp_lib_node_extract",
494 "values": { "c++17": 201606 },
495 "headers": ["map", "set", "unordered_map", "unordered_set"],
496 }, {
497 "name": "__cpp_lib_nonmember_container_access",
498 "values": { "c++17": 201411 },
499 "headers": ["array", "deque", "forward_list", "iterator", "list", "map", "regex", "set", "string", "unordered_map", "unordered_set", "vector"],
500 }, {
501 "name": "__cpp_lib_not_fn",
502 "values": { "c++17": 201603 },
503 "headers": ["functional"],
504 }, {
505 "name": "__cpp_lib_null_iterators",
506 "values": { "c++14": 201304 },
507 "headers": ["iterator"],
508 }, {
509 "name": "__cpp_lib_optional",
510 "values": { "c++17": 201606, "c++2b": 202110 },
511 "headers": ["optional"],
512 }, {
513 "name": "__cpp_lib_out_ptr",
514 "values": { "c++2b": 202106 },
515 "headers": ["memory"],
516 "unimplemented": True,
517 }, {
518 "name": "__cpp_lib_parallel_algorithm",
519 "values": { "c++17": 201603 },
520 "headers": ["algorithm", "numeric"],
521 "unimplemented": True,
522 }, {
523 "name": "__cpp_lib_polymorphic_allocator",
524 "values": { "c++20": 201902 },
525 "headers": ["memory_resource"],
526 "unimplemented": True,
527 }, {
528 "name": "__cpp_lib_quoted_string_io",
529 "values": { "c++14": 201304 },
530 "headers": ["iomanip"],
531 }, {
532 "name": "__cpp_lib_ranges",
533 "values": { "c++20": 201811 },
534 "headers": ["algorithm", "functional", "iterator", "memory", "ranges"],
535 }, {
536 "name": "__cpp_lib_ranges_chunk",
537 "values": { "c++2b": 202202 },
538 "headers": ["ranges"],
539 "unimplemented": True,
540 }, {
541 "name": "__cpp_lib_ranges_chunk_by",
542 "values": { "c++2b": 202202 },
543 "headers": ["ranges"],
544 "unimplemented": True,
545 }, {
546 "name": "__cpp_lib_ranges_iota",
547 "values": { "c++2b": 202202 },
548 "headers": ["numeric"],
549 "unimplemented": True,
550 }, {
551 "name": "__cpp_lib_ranges_join_with",
552 "values": { "c++2b": 202202 },
553 "headers": ["ranges"],
554 "unimplemented": True,
555 }, {
556 "name": "__cpp_lib_ranges_slide",
557 "values": { "c++2b": 202202 },
558 "headers": ["ranges"],
559 "unimplemented": True,
560 }, {
561 "name": "__cpp_lib_ranges_starts_ends_with",
562 "values": { "c++2b": 202106 },
563 "headers": ["algorithm"],
564 "unimplemented": True,
565 }, {
566 "name": "__cpp_lib_ranges_to_container",
567 "values": { "c++2b": 202202 },
568 "headers": ["deque", "forward_list", "list", "map", "priority_queue", "queue", "set", "stack", "string", "unordered_map", "unordered_set", "vector"],
569 "unimplemented": True,
570 }, {
571 "name": "__cpp_lib_ranges_zip",
572 "values": { "c++2b": 202110 },
573 "headers": ["ranges", "tuple", "utility"],
574 "unimplemented": True,
575 }, {
576 "name": "__cpp_lib_raw_memory_algorithms",
577 "values": { "c++17": 201606 },
578 "headers": ["memory"],
579 }, {
580 "name": "__cpp_lib_reference_from_temporary",
581 "values": { "c++2b": 202202 },
582 "headers": ["type_traits"],
583 "unimplemented": True,
584 }, {
585 "name": "__cpp_lib_remove_cvref",
586 "values": { "c++20": 201711 },
587 "headers": ["type_traits"],
588 }, {
589 "name": "__cpp_lib_result_of_sfinae",
590 "values": { "c++14": 201210 },
591 "headers": ["functional", "type_traits"],
592 }, {
593 "name": "__cpp_lib_robust_nonmodifying_seq_ops",
594 "values": { "c++14": 201304 },
595 "headers": ["algorithm"],
596 }, {
597 "name": "__cpp_lib_sample",
598 "values": { "c++17": 201603 },
599 "headers": ["algorithm"],
600 }, {
601 "name": "__cpp_lib_scoped_lock",
602 "values": { "c++17": 201703 },
603 "headers": ["mutex"],
604 }, {
605 "name": "__cpp_lib_semaphore",
606 "values": { "c++20": 201907 },
607 "headers": ["semaphore"],
608 "test_suite_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore)",
609 "libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_semaphore)",
610 }, {
611 "name": "__cpp_lib_shared_mutex",
612 "values": { "c++17": 201505 },
613 "headers": ["shared_mutex"],
614 "test_suite_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex)",
615 "libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_mutex)",
616 }, {
617 "name": "__cpp_lib_shared_ptr_arrays",
618 "values": { "c++17": 201611, "c++20": 201707 },
619 "headers": ["memory"],
620 }, {
621 "name": "__cpp_lib_shared_ptr_weak_type",
622 "values": { "c++17": 201606 },
623 "headers": ["memory"],
624 }, {
625 "name": "__cpp_lib_shared_timed_mutex",
626 "values": { "c++14": 201402 },
627 "headers": ["shared_mutex"],
628 "test_suite_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex)",
629 "libcxx_guard": "!defined(_LIBCPP_HAS_NO_THREADS) && !defined(_LIBCPP_AVAILABILITY_DISABLE_FTM___cpp_lib_shared_timed_mutex)",
630 }, {
631 "name": "__cpp_lib_shift",
632 "values": { "c++20": 201806 },
633 "headers": ["algorithm"],
634 }, {
635 "name": "__cpp_lib_smart_ptr_for_overwrite",
636 "values": { "c++20": 202002 },
637 "headers": ["memory"],
638 "unimplemented": True,
639 }, {
640 "name": "__cpp_lib_source_location",
641 "values": { "c++20": 201907 },
642 "headers": ["source_location"],
643 "unimplemented": True,
644 }, {
645 "name": "__cpp_lib_span",
646 "values": { "c++20": 202002 },
647 "headers": ["span"],
648 }, {
649 "name": "__cpp_lib_spanstream",
650 "values": { "c++2b": 202106 },
651 "headers": ["spanstream"],
652 "unimplemented": True,
653 }, {
654 "name": "__cpp_lib_ssize",
655 "values": { "c++20": 201902 },
656 "headers": ["iterator"],
657 }, {
658 "name": "__cpp_lib_stacktrace",
659 "values": { "c++2b": 202011 },
660 "headers": ["stacktrace"],
661 "unimplemented": True,
662 }, {
663 "name": "__cpp_lib_starts_ends_with",
664 "values": { "c++20": 201711 },
665 "headers": ["string", "string_view"],
666 }, {
667 "name": "__cpp_lib_stdatomic_h",
668 "values": { "c++2b": 202011 },
669 "headers": ["stdatomic.h"],
670 }, {
671 "name": "__cpp_lib_string_contains",
672 "values": { "c++2b": 202011 },
673 "headers": ["string", "string_view"],
674 }, {
675 "name": "__cpp_lib_string_resize_and_overwrite",
676 "values": { "c++2b": 202110 },
677 "headers": ["string"],
678 }, {
679 "name": "__cpp_lib_string_udls",
680 "values": { "c++14": 201304 },
681 "headers": ["string"],
682 }, {
683 "name": "__cpp_lib_string_view",
684 "values": { "c++17": 201606, "c++20": 201803 },
685 "headers": ["string", "string_view"],
686 }, {
687 "name": "__cpp_lib_syncbuf",
688 "values": { "c++20": 201803 },
689 "headers": ["syncstream"],
690 "unimplemented": True,
691 }, {
692 "name": "__cpp_lib_three_way_comparison",
693 "values": { "c++20": 201907 },
694 "headers": ["compare"],
695 "unimplemented": True,
696 }, {
697 "name": "__cpp_lib_to_address",
698 "values": { "c++20": 201711 },
699 "headers": ["memory"],
700 }, {
701 "name": "__cpp_lib_to_array",
702 "values": { "c++20": 201907 },
703 "headers": ["array"],
704 }, {
705 "name": "__cpp_lib_to_chars",
706 "values": { "c++17": 201611 },
707 "headers": ["charconv"],
708 "unimplemented": True,
709 }, {
710 "name": "__cpp_lib_to_underlying",
711 "values": { "c++2b": 202102 },
712 "headers": ["utility"],
713 }, {
714 "name": "__cpp_lib_transformation_trait_aliases",
715 "values": { "c++14": 201304 },
716 "headers": ["type_traits"],
717 }, {
718 "name": "__cpp_lib_transparent_operators",
719 "values": { "c++14": 201210, "c++17": 201510 },
720 "headers": ["functional", "memory"],
721 }, {
722 "name": "__cpp_lib_tuple_element_t",
723 "values": { "c++14": 201402 },
724 "headers": ["tuple"],
725 }, {
726 "name": "__cpp_lib_tuples_by_type",
727 "values": { "c++14": 201304 },
728 "headers": ["tuple", "utility"],
729 }, {
730 "name": "__cpp_lib_type_identity",
731 "values": { "c++20": 201806 },
732 "headers": ["type_traits"],
733 }, {
734 "name": "__cpp_lib_type_trait_variable_templates",
735 "values": { "c++17": 201510 },
736 "headers": ["type_traits"],
737 }, {
738 "name": "__cpp_lib_uncaught_exceptions",
739 "values": { "c++17": 201411 },
740 "headers": ["exception"],
741 }, {
742 "name": "__cpp_lib_unordered_map_try_emplace",
743 "values": { "c++17": 201411 },
744 "headers": ["unordered_map"],
745 }, {
746 "name": "__cpp_lib_unreachable",
747 "values": { "c++2b": 202202 },
748 "headers": ["utility"],
749 }, {
750 "name": "__cpp_lib_unwrap_ref",
751 "values": { "c++20": 201811 },
752 "headers": ["functional"],
753 }, {
754 "name": "__cpp_lib_variant",
755 "values": { "c++17": 202102 },
756 "headers": ["variant"],
757 }, {
758 "name": "__cpp_lib_void_t",
759 "values": { "c++17": 201411 },
760 "headers": ["type_traits"],
764 assert feature_test_macros == sorted(feature_test_macros, key=lambda tc: tc["name"])
765 assert all(tc["headers"] == sorted(tc["headers"]) for tc in feature_test_macros)
766 assert all(("libcxx_guard" in tc) == ("test_suite_guard" in tc) for tc in feature_test_macros)
767 assert all(all(key in ["name", "values", "headers", "libcxx_guard", "test_suite_guard", "unimplemented"] for key in tc.keys()) for tc in feature_test_macros)
769 # Map from each header to the Lit annotations that should be used for
770 # tests that include that header.
772 # For example, when threads are not supported, any test that includes
773 # <thread> should be marked as UNSUPPORTED, because including <thread>
774 # is a hard error in that case.
775 lit_markup = {
776 "barrier": ["UNSUPPORTED: no-threads"],
777 "filesystem": ["UNSUPPORTED: no-filesystem"],
778 "format": ["UNSUPPORTED: libcpp-has-no-incomplete-format"],
779 "iomanip": ["UNSUPPORTED: no-localization"],
780 "ios": ["UNSUPPORTED: no-localization"],
781 "iostream": ["UNSUPPORTED: no-localization"],
782 "istream": ["UNSUPPORTED: no-localization"],
783 "latch": ["UNSUPPORTED: no-threads"],
784 "locale": ["UNSUPPORTED: no-localization"],
785 "mutex": ["UNSUPPORTED: no-threads"],
786 "ostream": ["UNSUPPORTED: no-localization"],
787 "regex": ["UNSUPPORTED: no-localization"],
788 "semaphore": ["UNSUPPORTED: no-threads"],
789 "shared_mutex": ["UNSUPPORTED: no-threads"],
790 "stdatomic.h": ["UNSUPPORTED: no-threads"],
791 "thread": ["UNSUPPORTED: no-threads"],
794 def get_std_dialects():
795 std_dialects = ['c++14', 'c++17', 'c++20', 'c++2b']
796 return list(std_dialects)
798 def get_first_std(d):
799 for s in get_std_dialects():
800 if s in d.keys():
801 return s
802 return None
804 def get_last_std(d):
805 rev_dialects = get_std_dialects()
806 rev_dialects.reverse()
807 for s in rev_dialects:
808 if s in d.keys():
809 return s
810 return None
812 def get_std_before(d, std):
813 std_dialects = get_std_dialects()
814 candidates = std_dialects[0:std_dialects.index(std)]
815 candidates.reverse()
816 for cand in candidates:
817 if cand in d.keys():
818 return cand
819 return None
821 def get_value_before(d, std):
822 new_std = get_std_before(d, std)
823 if new_std is None:
824 return None
825 return d[new_std]
827 def get_for_std(d, std):
828 # This catches the C++11 case for which there should be no defined feature
829 # test macros.
830 std_dialects = get_std_dialects()
831 if std not in std_dialects:
832 return None
833 # Find the value for the newest C++ dialect between C++14 and std
834 std_list = list(std_dialects[0:std_dialects.index(std)+1])
835 std_list.reverse()
836 for s in std_list:
837 if s in d.keys():
838 return d[s]
839 return None
841 def get_std_number(std):
842 return std.replace('c++', '')
845 Functions to produce the <version> header
848 def produce_macros_definition_for_std(std):
849 result = ""
850 indent = 55
851 for tc in feature_test_macros:
852 if std not in tc["values"]:
853 continue
854 inner_indent = 1
855 if 'test_suite_guard' in tc.keys():
856 result += "# if %s\n" % tc["libcxx_guard"]
857 inner_indent += 2
858 if get_value_before(tc["values"], std) is not None:
859 assert 'test_suite_guard' not in tc.keys()
860 result += "# undef %s\n" % tc["name"]
861 line = "#%sdefine %s" % ((" " * inner_indent), tc["name"])
862 line += " " * (indent - len(line))
863 line += " %sL" % tc["values"][std]
864 if 'unimplemented' in tc.keys():
865 line = "// " + line
866 result += line
867 result += "\n"
868 if 'test_suite_guard' in tc.keys():
869 result += "# endif\n"
870 return result.strip()
872 def produce_macros_definitions():
873 macro_definition_template = """#if _LIBCPP_STD_VER > {previous_std_number}
874 {macro_definition}
875 #endif"""
877 macros_definitions = []
878 previous_std_number = '11'
879 for std in get_std_dialects():
880 macros_definitions.append(
881 macro_definition_template.format(previous_std_number=previous_std_number,
882 macro_definition=produce_macros_definition_for_std(std)))
883 previous_std_number = get_std_number(std)
885 return '\n\n'.join(macros_definitions)
887 def chunks(l, n):
888 """Yield successive n-sized chunks from l."""
889 for i in range(0, len(l), n):
890 yield l[i:i + n]
892 def produce_version_synopsis():
893 indent = 56
894 header_indent = 56 + len("20XXYYL ")
895 result = ""
896 def indent_to(s, val):
897 if len(s) >= val:
898 return s
899 s += " " * (val - len(s))
900 return s
901 line = indent_to("Macro name", indent) + "Value"
902 line = indent_to(line, header_indent) + "Headers"
903 result += line + "\n"
904 for tc in feature_test_macros:
905 prev_defined_std = get_last_std(tc["values"])
906 line = "{name: <{indent}}{value}L ".format(name=tc['name'], indent=indent,
907 value=tc["values"][prev_defined_std])
908 headers = list(tc["headers"])
909 headers.remove("version")
910 for chunk in chunks(headers, 3):
911 line = indent_to(line, header_indent)
912 chunk = ['<%s>' % header for header in chunk]
913 line += ' '.join(chunk)
914 result += line
915 result += "\n"
916 line = ""
917 while True:
918 prev_defined_std = get_std_before(tc["values"], prev_defined_std)
919 if prev_defined_std is None:
920 break
921 result += "%s%sL // %s\n" % (indent_to("", indent), tc["values"][prev_defined_std],
922 prev_defined_std.replace("c++", "C++"))
923 return result
926 def produce_version_header():
927 template="""// -*- C++ -*-
928 //===----------------------------------------------------------------------===//
930 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
931 // See https://llvm.org/LICENSE.txt for license information.
932 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
934 //===----------------------------------------------------------------------===//
936 #ifndef _LIBCPP_VERSIONH
937 #define _LIBCPP_VERSIONH
940 version synopsis
942 {synopsis}
946 #include <__assert> // all public C++ headers provide the assertion handler
947 #include <__config>
949 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
950 # pragma GCC system_header
951 #endif
953 // clang-format off
955 {cxx_macros}
957 // clang-format on
959 #endif // _LIBCPP_VERSIONH
962 version_str = template.format(
963 synopsis=produce_version_synopsis().strip(),
964 cxx_macros=produce_macros_definitions())
965 version_header_path = os.path.join(include_path, 'version')
966 with open(version_header_path, 'w', newline='\n') as f:
967 f.write(version_str)
971 Functions to produce test files
974 test_types = {
975 "undefined": """
976 # ifdef {name}
977 # error "{name} should not be defined before {std_first}"
978 # endif
979 """,
981 "test_suite_guard": """
982 # if {test_suite_guard}
983 # ifndef {name}
984 # error "{name} should be defined in {std}"
985 # endif
986 # if {name} != {value}
987 # error "{name} should have the value {value} in {std}"
988 # endif
989 # else
990 # ifdef {name}
991 # error "{name} should not be defined when the requirement '{test_suite_guard}' is not met!"
992 # endif
993 # endif
994 """,
996 "unimplemented": """
997 # if !defined(_LIBCPP_VERSION)
998 # ifndef {name}
999 # error "{name} should be defined in {std}"
1000 # endif
1001 # if {name} != {value}
1002 # error "{name} should have the value {value} in {std}"
1003 # endif
1004 # else // _LIBCPP_VERSION
1005 # ifdef {name}
1006 # error "{name} should not be defined because it is unimplemented in libc++!"
1007 # endif
1008 # endif
1009 """,
1011 "defined": """
1012 # ifndef {name}
1013 # error "{name} should be defined in {std}"
1014 # endif
1015 # if {name} != {value}
1016 # error "{name} should have the value {value} in {std}"
1017 # endif
1021 def generate_std_test(test_list, std):
1022 result = ""
1023 for tc in test_list:
1024 val = get_for_std(tc["values"], std)
1025 if val is not None:
1026 val = "%sL" % val
1027 if val is None:
1028 result += test_types["undefined"].format(name=tc["name"], std_first=get_first_std(tc["values"]))
1029 elif 'unimplemented' in tc.keys():
1030 result += test_types["unimplemented"].format(name=tc["name"], value=val, std=std)
1031 elif "test_suite_guard" in tc.keys():
1032 result += test_types["test_suite_guard"].format(name=tc["name"], value=val, std=std, test_suite_guard=tc["test_suite_guard"])
1033 else:
1034 result += test_types["defined"].format(name=tc["name"], value=val, std=std)
1035 return result.strip()
1037 def generate_std_tests(test_list):
1038 std_tests_template = """#if TEST_STD_VER < {first_std_number}
1040 {pre_std_test}
1042 {other_std_tests}
1044 #elif TEST_STD_VER > {penultimate_std_number}
1046 {last_std_test}
1048 #endif // TEST_STD_VER > {penultimate_std_number}"""
1050 std_dialects = get_std_dialects()
1051 assert not get_std_number(std_dialects[-1]).isnumeric()
1053 other_std_tests = []
1054 for std in std_dialects[:-1]:
1055 other_std_tests.append('#elif TEST_STD_VER == ' + get_std_number(std))
1056 other_std_tests.append(generate_std_test(test_list, std))
1058 std_tests = std_tests_template.format(first_std_number=get_std_number(std_dialects[0]),
1059 pre_std_test=generate_std_test(test_list, 'c++11'),
1060 other_std_tests='\n\n'.join(other_std_tests),
1061 penultimate_std_number=get_std_number(std_dialects[-2]),
1062 last_std_test=generate_std_test(test_list, std_dialects[-1]))
1064 return std_tests
1066 def generate_synopsis(test_list):
1067 max_name_len = max([len(tc["name"]) for tc in test_list])
1068 indent = max_name_len + 8
1069 def mk_line(prefix, suffix):
1070 return "{prefix: <{max_len}}{suffix}\n".format(prefix=prefix, suffix=suffix,
1071 max_len=indent)
1072 result = ""
1073 result += mk_line("/* Constant", "Value")
1074 for tc in test_list:
1075 prefix = " %s" % tc["name"]
1076 for std in [s for s in get_std_dialects() if s in tc["values"].keys()]:
1077 result += mk_line(prefix, "%sL [%s]" % (tc["values"][std], std.replace("c++", "C++")))
1078 prefix = ""
1079 result += "*/"
1080 return result
1082 def produce_tests():
1083 headers = set([h for tc in feature_test_macros for h in tc["headers"]])
1084 for h in headers:
1085 test_list = [tc for tc in feature_test_macros if h in tc["headers"]]
1086 if not has_header(h):
1087 for tc in test_list:
1088 assert 'unimplemented' in tc.keys()
1089 continue
1090 markup = '\n'.join('// ' + tag for tag in lit_markup.get(h, []))
1091 test_body = \
1092 """//===----------------------------------------------------------------------===//
1094 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
1095 // See https://llvm.org/LICENSE.txt for license information.
1096 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1098 //===----------------------------------------------------------------------===//
1100 // WARNING: This test was generated by {script_name}
1101 // and should not be edited manually.
1103 // clang-format off
1104 {markup}
1105 // <{header}>
1107 // Test the feature test macros defined by <{header}>
1109 {synopsis}
1111 #include <{header}>
1112 #include "test_macros.h"
1114 {cxx_tests}
1116 """.format(script_name=script_name,
1117 header=h,
1118 markup=('\n{}\n'.format(markup) if markup else ''),
1119 synopsis=generate_synopsis(test_list),
1120 cxx_tests=generate_std_tests(test_list))
1121 test_name = "{header}.version.compile.pass.cpp".format(header=h)
1122 out_path = os.path.join(macro_test_path, test_name)
1123 with open(out_path, 'w', newline='\n') as f:
1124 f.write(test_body)
1127 Produce documentation for the feature test macros
1130 def make_widths(grid):
1131 widths = []
1132 for i in range(0, len(grid[0])):
1133 cell_width = 2 + max(reduce(lambda x,y: x+y, [[len(row[i])] for row in grid], []))
1134 widths += [cell_width]
1135 return widths
1137 def create_table(grid, indent):
1138 indent_str = ' '*indent
1139 col_widths = make_widths(grid)
1140 result = [indent_str + add_divider(col_widths, 2)]
1141 header_flag = 2
1142 for row_i in range(0, len(grid)):
1143 row = grid[row_i]
1144 line = indent_str + ' '.join([pad_cell(row[i], col_widths[i]) for i in range(0, len(row))])
1145 result.append(line.rstrip())
1146 is_cxx_header = row[0].startswith('**')
1147 if row_i == len(grid) - 1:
1148 header_flag = 2
1149 separator = indent_str + add_divider(col_widths, 1 if is_cxx_header else header_flag)
1150 result.append(separator.rstrip())
1151 header_flag = 0
1152 return '\n'.join(result)
1154 def add_divider(widths, header_flag):
1155 if header_flag == 2:
1156 return ' '.join(['='*w for w in widths])
1157 if header_flag == 1:
1158 return '-'.join(['-'*w for w in widths])
1159 else:
1160 return ' '.join(['-'*w for w in widths])
1162 def pad_cell(s, length, left_align=True):
1163 padding = ((length - len(s)) * ' ')
1164 return s + padding
1167 def get_status_table():
1168 table = [["Macro Name", "Value"]]
1169 for std in get_std_dialects():
1170 table += [["**" + std.replace("c++", "C++ ") + "**", ""]]
1171 for tc in feature_test_macros:
1172 if std not in tc["values"].keys():
1173 continue
1174 value = "``%sL``" % tc["values"][std]
1175 if 'unimplemented' in tc.keys():
1176 value = '*unimplemented*'
1177 table += [["``%s``" % tc["name"], value]]
1178 return table
1180 def produce_docs():
1181 doc_str = """.. _FeatureTestMacroTable:
1183 ==========================
1184 Feature Test Macro Support
1185 ==========================
1187 .. contents::
1188 :local:
1190 Overview
1191 ========
1193 This file documents the feature test macros currently supported by libc++.
1195 .. _feature-status:
1197 Status
1198 ======
1200 .. table:: Current Status
1201 :name: feature-status-table
1202 :widths: auto
1204 {status_tables}
1206 """.format(status_tables=create_table(get_status_table(), 4))
1208 table_doc_path = os.path.join(docs_path, 'FeatureTestMacroTable.rst')
1209 with open(table_doc_path, 'w', newline='\n') as f:
1210 f.write(doc_str)
1212 def main():
1213 produce_version_header()
1214 produce_tests()
1215 produce_docs()
1218 if __name__ == '__main__':
1219 main()