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()
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")
32 # ================ ============================================================
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
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
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"],
70 "name": "__cpp_lib_addressof_constexpr",
71 "values": { "c++17": 201603 },
72 "headers": ["memory"],
74 "name": "__cpp_lib_allocate_at_least",
75 "values": { "c++2b": 202106 },
76 "headers": ["memory"],
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"],
82 "name": "__cpp_lib_any",
83 "values": { "c++17": 201606 },
86 "name": "__cpp_lib_apply",
87 "values": { "c++17": 201603 },
90 "name": "__cpp_lib_array_constexpr",
91 "values": { "c++17": 201603, "c++20": 201811 },
92 "headers": ["array", "iterator"],
94 "name": "__cpp_lib_as_const",
95 "values": { "c++17": 201510 },
96 "headers": ["utility"],
98 "name": "__cpp_lib_associative_heterogeneous_erasure",
99 "values": { "c++2b": 202110 },
100 "headers": ["map", "set", "unordered_map", "unordered_set"],
101 "unimplemented": True,
103 "name": "__cpp_lib_assume_aligned",
104 "values": { "c++20": 201811 },
105 "headers": ["memory"],
107 "name": "__cpp_lib_atomic_flag_test",
108 "values": { "c++20": 201907 },
109 "headers": ["atomic"],
111 "name": "__cpp_lib_atomic_float",
112 "values": { "c++20": 201711 },
113 "headers": ["atomic"],
114 "unimplemented": True,
116 "name": "__cpp_lib_atomic_is_always_lock_free",
117 "values": { "c++17": 201603 },
118 "headers": ["atomic"],
120 "name": "__cpp_lib_atomic_lock_free_type_aliases",
121 "values": { "c++20": 201907 },
122 "headers": ["atomic"],
124 "name": "__cpp_lib_atomic_ref",
125 "values": { "c++20": 201806 },
126 "headers": ["atomic"],
127 "unimplemented": True,
129 "name": "__cpp_lib_atomic_shared_ptr",
130 "values": { "c++20": 201711 },
131 "headers": ["atomic"],
132 "unimplemented": True,
134 "name": "__cpp_lib_atomic_value_initialization",
135 "values": { "c++20": 201911 },
136 "headers": ["atomic", "memory"],
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)",
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)",
150 "name": "__cpp_lib_bind_back",
151 "values": { "c++2b": 202202 },
152 "headers": ["functional"],
153 "unimplemented": True,
155 "name": "__cpp_lib_bind_front",
156 "values": { "c++20": 201907 },
157 "headers": ["functional"],
159 "name": "__cpp_lib_bit_cast",
160 "values": { "c++20": 201806 },
163 "name": "__cpp_lib_bitops",
164 "values": { "c++20": 201907 },
166 "unimplemented": True,
168 "name": "__cpp_lib_bool_constant",
169 "values": { "c++17": 201505 },
170 "headers": ["type_traits"],
172 "name": "__cpp_lib_bounded_array_traits",
173 "values": { "c++20": 201902 },
174 "headers": ["type_traits"],
176 "name": "__cpp_lib_boyer_moore_searcher",
177 "values": { "c++17": 201603 },
178 "headers": ["functional"],
180 "name": "__cpp_lib_byte",
181 "values": { "c++17": 201603 },
182 "headers": ["cstddef"],
184 "name": "__cpp_lib_byteswap",
185 "values": { "c++2b": 202110 },
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)",
194 "name": "__cpp_lib_chrono",
195 "values": { "c++17": 201611 },
196 "headers": ["chrono"],
198 "name": "__cpp_lib_chrono_udls",
199 "values": { "c++14": 201304 },
200 "headers": ["chrono"],
202 "name": "__cpp_lib_clamp",
203 "values": { "c++17": 201603 },
204 "headers": ["algorithm"],
206 "name": "__cpp_lib_complex_udls",
207 "values": { "c++14": 201309 },
208 "headers": ["complex"],
210 "name": "__cpp_lib_concepts",
211 "values": { "c++20": 202002 },
212 "headers": ["concepts"],
214 "name": "__cpp_lib_constexpr_algorithms",
215 "values": { "c++20": 201806 },
216 "headers": ["algorithm"],
218 "name": "__cpp_lib_constexpr_bitset",
219 "values": { "c++2b": 202207 },
220 "headers": ["bitset"],
222 "name": "__cpp_lib_constexpr_cmath",
223 "values": { "c++2b": 202202 },
224 "headers": ["cmath", "cstdlib"],
225 "unimplemented": True,
227 "name": "__cpp_lib_constexpr_complex",
228 "values": { "c++20": 201711 },
229 "headers": ["complex"],
230 "unimplemented": True,
232 "name": "__cpp_lib_constexpr_dynamic_alloc",
233 "values": { "c++20": 201907 },
234 "headers": ["memory"],
236 "name": "__cpp_lib_constexpr_functional",
237 "values": { "c++20": 201907 },
238 "headers": ["functional"],
240 "name": "__cpp_lib_constexpr_iterator",
241 "values": { "c++20": 201811 },
242 "headers": ["iterator"],
244 "name": "__cpp_lib_constexpr_memory",
245 "values": { "c++20": 201811, "c++2b": 202202 },
246 "headers": ["memory"],
248 "name": "__cpp_lib_constexpr_numeric",
249 "values": { "c++20": 201911 },
250 "headers": ["numeric"],
252 "name": "__cpp_lib_constexpr_string",
253 "values": { "c++20": 201907 },
254 "headers": ["string"],
256 "name": "__cpp_lib_constexpr_string_view",
257 "values": { "c++20": 201811 },
258 "headers": ["string_view"],
260 "name": "__cpp_lib_constexpr_tuple",
261 "values": { "c++20": 201811 },
262 "headers": ["tuple"],
264 "name": "__cpp_lib_constexpr_typeinfo",
265 "values": { "c++2b": 202106 },
266 "headers": ["typeinfo"],
267 "unimplemented": True,
269 "name": "__cpp_lib_constexpr_utility",
270 "values": { "c++20": 201811 },
271 "headers": ["utility"],
273 "name": "__cpp_lib_constexpr_vector",
274 "values": { "c++20": 201907 },
275 "headers": ["vector"],
276 "unimplemented": True,
278 "name": "__cpp_lib_coroutine",
279 "values": { "c++20": 201902 },
280 "headers": ["coroutine"],
282 "name": "__cpp_lib_destroying_delete",
283 "values": { "c++20": 201806 },
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",
288 "name": "__cpp_lib_enable_shared_from_this",
289 "values": { "c++17": 201603 },
290 "headers": ["memory"],
292 "name": "__cpp_lib_endian",
293 "values": { "c++20": 201907 },
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"],
300 "name": "__cpp_lib_exchange_function",
301 "values": { "c++14": 201304 },
302 "headers": ["utility"],
304 "name": "__cpp_lib_execution",
305 "values": { "c++17": 201603, "c++20": 201902 },
306 "headers": ["execution"],
307 "unimplemented": True,
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)"
315 "name": "__cpp_lib_format",
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
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,
328 "name": "__cpp_lib_forward_like",
329 "values": { "c++2b": 202207 },
330 "headers": ["utility"],
332 "name": "__cpp_lib_gcd_lcm",
333 "values": { "c++17": 201606 },
334 "headers": ["numeric"],
336 "name": "__cpp_lib_generic_associative_lookup",
337 "values": { "c++14": 201304 },
338 "headers": ["map", "set"],
340 "name": "__cpp_lib_generic_unordered_lookup",
341 "values": { "c++20": 201811 },
342 "headers": ["unordered_map", "unordered_set"],
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)",
350 "name": "__cpp_lib_has_unique_object_representations",
351 "values": { "c++17": 201606 },
352 "headers": ["type_traits"],
354 "name": "__cpp_lib_hypot",
355 "values": { "c++17": 201603 },
356 "headers": ["cmath"],
358 "name": "__cpp_lib_incomplete_container_elements",
359 "values": { "c++17": 201505 },
360 "headers": ["forward_list", "list", "vector"],
362 "name": "__cpp_lib_int_pow2",
363 "values": { "c++20": 202002 },
366 "name": "__cpp_lib_integer_comparison_functions",
367 "values": { "c++20": 202002 },
368 "headers": ["utility"],
370 "name": "__cpp_lib_integer_sequence",
371 "values": { "c++14": 201304 },
372 "headers": ["utility"],
374 "name": "__cpp_lib_integral_constant_callable",
375 "values": { "c++14": 201304 },
376 "headers": ["type_traits"],
378 "name": "__cpp_lib_interpolate",
379 "values": { "c++20": 201902 },
380 "headers": ["cmath", "numeric"],
382 "name": "__cpp_lib_invoke",
383 "values": { "c++17": 201411 },
384 "headers": ["functional"],
386 "name": "__cpp_lib_invoke_r",
387 "values": { "c++2b": 202106 },
388 "headers": ["functional"],
389 "unimplemented": True,
391 "name": "__cpp_lib_is_aggregate",
392 "values": { "c++17": 201703 },
393 "headers": ["type_traits"],
395 "name": "__cpp_lib_is_constant_evaluated",
396 "values": { "c++20": 201811 },
397 "headers": ["type_traits"],
399 "name": "__cpp_lib_is_final",
400 "values": { "c++14": 201402 },
401 "headers": ["type_traits"],
403 "name": "__cpp_lib_is_invocable",
404 "values": { "c++17": 201703 },
405 "headers": ["type_traits"],
407 "name": "__cpp_lib_is_layout_compatible",
408 "values": { "c++20": 201907 },
409 "headers": ["type_traits"],
410 "unimplemented": True,
412 "name": "__cpp_lib_is_nothrow_convertible",
413 "values": { "c++20": 201806 },
414 "headers": ["type_traits"],
416 "name": "__cpp_lib_is_null_pointer",
417 "values": { "c++14": 201309 },
418 "headers": ["type_traits"],
420 "name": "__cpp_lib_is_pointer_interconvertible",
421 "values": { "c++20": 201907 },
422 "headers": ["type_traits"],
423 "unimplemented": True,
425 "name": "__cpp_lib_is_scoped_enum",
426 "values": { "c++2b": 202011 },
427 "headers": ["type_traits"],
429 "name": "__cpp_lib_is_swappable",
430 "values": { "c++17": 201603 },
431 "headers": ["type_traits"],
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,
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)",
446 "name": "__cpp_lib_launder",
447 "values": { "c++17": 201606 },
450 "name": "__cpp_lib_list_remove_return_type",
451 "values": { "c++20": 201806 },
452 "headers": ["forward_list", "list"],
454 "name": "__cpp_lib_logical_traits",
455 "values": { "c++17": 201510 },
456 "headers": ["type_traits"],
458 "name": "__cpp_lib_make_from_tuple",
459 "values": { "c++17": 201606 },
460 "headers": ["tuple"],
462 "name": "__cpp_lib_make_reverse_iterator",
463 "values": { "c++14": 201402 },
464 "headers": ["iterator"],
466 "name": "__cpp_lib_make_unique",
467 "values": { "c++14": 201304 },
468 "headers": ["memory"],
470 "name": "__cpp_lib_map_try_emplace",
471 "values": { "c++17": 201411 },
474 "name": "__cpp_lib_math_constants",
475 "values": { "c++20": 201907 },
476 "headers": ["numbers"],
478 "name": "__cpp_lib_math_special_functions",
479 "values": { "c++17": 201603 },
480 "headers": ["cmath"],
481 "unimplemented": True,
483 "name": "__cpp_lib_memory_resource",
484 "values": { "c++17": 201603 },
485 "headers": ["memory_resource"],
486 "unimplemented": True,
488 "name": "__cpp_lib_move_only_function",
489 "values": { "c++2b": 202110 },
490 "headers": ["functional"],
491 "unimplemented": True,
493 "name": "__cpp_lib_node_extract",
494 "values": { "c++17": 201606 },
495 "headers": ["map", "set", "unordered_map", "unordered_set"],
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"],
501 "name": "__cpp_lib_not_fn",
502 "values": { "c++17": 201603 },
503 "headers": ["functional"],
505 "name": "__cpp_lib_null_iterators",
506 "values": { "c++14": 201304 },
507 "headers": ["iterator"],
509 "name": "__cpp_lib_optional",
510 "values": { "c++17": 201606, "c++2b": 202110 },
511 "headers": ["optional"],
513 "name": "__cpp_lib_out_ptr",
514 "values": { "c++2b": 202106 },
515 "headers": ["memory"],
516 "unimplemented": True,
518 "name": "__cpp_lib_parallel_algorithm",
519 "values": { "c++17": 201603 },
520 "headers": ["algorithm", "numeric"],
521 "unimplemented": True,
523 "name": "__cpp_lib_polymorphic_allocator",
524 "values": { "c++20": 201902 },
525 "headers": ["memory_resource"],
526 "unimplemented": True,
528 "name": "__cpp_lib_quoted_string_io",
529 "values": { "c++14": 201304 },
530 "headers": ["iomanip"],
532 "name": "__cpp_lib_ranges",
533 "values": { "c++20": 201811 },
534 "headers": ["algorithm", "functional", "iterator", "memory", "ranges"],
536 "name": "__cpp_lib_ranges_chunk",
537 "values": { "c++2b": 202202 },
538 "headers": ["ranges"],
539 "unimplemented": True,
541 "name": "__cpp_lib_ranges_chunk_by",
542 "values": { "c++2b": 202202 },
543 "headers": ["ranges"],
544 "unimplemented": True,
546 "name": "__cpp_lib_ranges_iota",
547 "values": { "c++2b": 202202 },
548 "headers": ["numeric"],
549 "unimplemented": True,
551 "name": "__cpp_lib_ranges_join_with",
552 "values": { "c++2b": 202202 },
553 "headers": ["ranges"],
554 "unimplemented": True,
556 "name": "__cpp_lib_ranges_slide",
557 "values": { "c++2b": 202202 },
558 "headers": ["ranges"],
559 "unimplemented": True,
561 "name": "__cpp_lib_ranges_starts_ends_with",
562 "values": { "c++2b": 202106 },
563 "headers": ["algorithm"],
564 "unimplemented": True,
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,
571 "name": "__cpp_lib_ranges_zip",
572 "values": { "c++2b": 202110 },
573 "headers": ["ranges", "tuple", "utility"],
574 "unimplemented": True,
576 "name": "__cpp_lib_raw_memory_algorithms",
577 "values": { "c++17": 201606 },
578 "headers": ["memory"],
580 "name": "__cpp_lib_reference_from_temporary",
581 "values": { "c++2b": 202202 },
582 "headers": ["type_traits"],
583 "unimplemented": True,
585 "name": "__cpp_lib_remove_cvref",
586 "values": { "c++20": 201711 },
587 "headers": ["type_traits"],
589 "name": "__cpp_lib_result_of_sfinae",
590 "values": { "c++14": 201210 },
591 "headers": ["functional", "type_traits"],
593 "name": "__cpp_lib_robust_nonmodifying_seq_ops",
594 "values": { "c++14": 201304 },
595 "headers": ["algorithm"],
597 "name": "__cpp_lib_sample",
598 "values": { "c++17": 201603 },
599 "headers": ["algorithm"],
601 "name": "__cpp_lib_scoped_lock",
602 "values": { "c++17": 201703 },
603 "headers": ["mutex"],
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)",
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)",
617 "name": "__cpp_lib_shared_ptr_arrays",
618 "values": { "c++17": 201611, "c++20": 201707 },
619 "headers": ["memory"],
621 "name": "__cpp_lib_shared_ptr_weak_type",
622 "values": { "c++17": 201606 },
623 "headers": ["memory"],
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)",
631 "name": "__cpp_lib_shift",
632 "values": { "c++20": 201806 },
633 "headers": ["algorithm"],
635 "name": "__cpp_lib_smart_ptr_for_overwrite",
636 "values": { "c++20": 202002 },
637 "headers": ["memory"],
638 "unimplemented": True,
640 "name": "__cpp_lib_source_location",
641 "values": { "c++20": 201907 },
642 "headers": ["source_location"],
643 "unimplemented": True,
645 "name": "__cpp_lib_span",
646 "values": { "c++20": 202002 },
649 "name": "__cpp_lib_spanstream",
650 "values": { "c++2b": 202106 },
651 "headers": ["spanstream"],
652 "unimplemented": True,
654 "name": "__cpp_lib_ssize",
655 "values": { "c++20": 201902 },
656 "headers": ["iterator"],
658 "name": "__cpp_lib_stacktrace",
659 "values": { "c++2b": 202011 },
660 "headers": ["stacktrace"],
661 "unimplemented": True,
663 "name": "__cpp_lib_starts_ends_with",
664 "values": { "c++20": 201711 },
665 "headers": ["string", "string_view"],
667 "name": "__cpp_lib_stdatomic_h",
668 "values": { "c++2b": 202011 },
669 "headers": ["stdatomic.h"],
671 "name": "__cpp_lib_string_contains",
672 "values": { "c++2b": 202011 },
673 "headers": ["string", "string_view"],
675 "name": "__cpp_lib_string_resize_and_overwrite",
676 "values": { "c++2b": 202110 },
677 "headers": ["string"],
679 "name": "__cpp_lib_string_udls",
680 "values": { "c++14": 201304 },
681 "headers": ["string"],
683 "name": "__cpp_lib_string_view",
684 "values": { "c++17": 201606, "c++20": 201803 },
685 "headers": ["string", "string_view"],
687 "name": "__cpp_lib_syncbuf",
688 "values": { "c++20": 201803 },
689 "headers": ["syncstream"],
690 "unimplemented": True,
692 "name": "__cpp_lib_three_way_comparison",
693 "values": { "c++20": 201907 },
694 "headers": ["compare"],
695 "unimplemented": True,
697 "name": "__cpp_lib_to_address",
698 "values": { "c++20": 201711 },
699 "headers": ["memory"],
701 "name": "__cpp_lib_to_array",
702 "values": { "c++20": 201907 },
703 "headers": ["array"],
705 "name": "__cpp_lib_to_chars",
706 "values": { "c++17": 201611 },
707 "headers": ["charconv"],
708 "unimplemented": True,
710 "name": "__cpp_lib_to_underlying",
711 "values": { "c++2b": 202102 },
712 "headers": ["utility"],
714 "name": "__cpp_lib_transformation_trait_aliases",
715 "values": { "c++14": 201304 },
716 "headers": ["type_traits"],
718 "name": "__cpp_lib_transparent_operators",
719 "values": { "c++14": 201210, "c++17": 201510 },
720 "headers": ["functional", "memory"],
722 "name": "__cpp_lib_tuple_element_t",
723 "values": { "c++14": 201402 },
724 "headers": ["tuple"],
726 "name": "__cpp_lib_tuples_by_type",
727 "values": { "c++14": 201304 },
728 "headers": ["tuple", "utility"],
730 "name": "__cpp_lib_type_identity",
731 "values": { "c++20": 201806 },
732 "headers": ["type_traits"],
734 "name": "__cpp_lib_type_trait_variable_templates",
735 "values": { "c++17": 201510 },
736 "headers": ["type_traits"],
738 "name": "__cpp_lib_uncaught_exceptions",
739 "values": { "c++17": 201411 },
740 "headers": ["exception"],
742 "name": "__cpp_lib_unordered_map_try_emplace",
743 "values": { "c++17": 201411 },
744 "headers": ["unordered_map"],
746 "name": "__cpp_lib_unreachable",
747 "values": { "c++2b": 202202 },
748 "headers": ["utility"],
750 "name": "__cpp_lib_unwrap_ref",
751 "values": { "c++20": 201811 },
752 "headers": ["functional"],
754 "name": "__cpp_lib_variant",
755 "values": { "c++17": 202102 },
756 "headers": ["variant"],
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.
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():
805 rev_dialects
= get_std_dialects()
806 rev_dialects
.reverse()
807 for s
in rev_dialects
:
812 def get_std_before(d
, std
):
813 std_dialects
= get_std_dialects()
814 candidates
= std_dialects
[0:std_dialects
.index(std
)]
816 for cand
in candidates
:
821 def get_value_before(d
, std
):
822 new_std
= get_std_before(d
, std
)
827 def get_for_std(d
, std
):
828 # This catches the C++11 case for which there should be no defined feature
830 std_dialects
= get_std_dialects()
831 if std
not in std_dialects
:
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])
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
):
851 for tc
in feature_test_macros
:
852 if std
not in tc
["values"]:
855 if 'test_suite_guard' in tc
.keys():
856 result
+= "# if %s\n" % tc
["libcxx_guard"]
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():
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}
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
)
888 """Yield successive n-sized chunks from l."""
889 for i
in range(0, len(l
), n
):
892 def produce_version_synopsis():
894 header_indent
= 56 + len("20XXYYL ")
896 def indent_to(s
, val
):
899 s
+= " " * (val
- len(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
)
918 prev_defined_std
= get_std_before(tc
["values"], prev_defined_std
)
919 if prev_defined_std
is None:
921 result
+= "%s%sL // %s\n" % (indent_to("", indent
), tc
["values"][prev_defined_std
],
922 prev_defined_std
.replace("c++", "C++"))
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
946 #include <__assert> // all public C++ headers provide the assertion handler
949 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
950 # pragma GCC system_header
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
:
971 Functions to produce test files
977 # error "{name} should not be defined before {std_first}"
981 "test_suite_guard": """
982 # if {test_suite_guard}
984 # error "{name} should be defined in {std}"
986 # if {name} != {value}
987 # error "{name} should have the value {value} in {std}"
991 # error "{name} should not be defined when the requirement '{test_suite_guard}' is not met!"
997 # if !defined(_LIBCPP_VERSION)
999 # error "{name} should be defined in {std}"
1001 # if {name} != {value}
1002 # error "{name} should have the value {value} in {std}"
1004 # else // _LIBCPP_VERSION
1006 # error "{name} should not be defined because it is unimplemented in libc++!"
1013 # error "{name} should be defined in {std}"
1015 # if {name} != {value}
1016 # error "{name} should have the value {value} in {std}"
1021 def generate_std_test(test_list
, std
):
1023 for tc
in test_list
:
1024 val
= get_for_std(tc
["values"], std
)
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"])
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}
1044 #elif TEST_STD_VER > {penultimate_std_number}
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]))
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
,
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++")))
1082 def produce_tests():
1083 headers
= set([h
for tc
in feature_test_macros
for h
in tc
["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()
1090 markup
= '\n'.join('// ' + tag
for tag
in lit_markup
.get(h
, []))
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.
1107 // Test the feature test macros defined by <{header}>
1112 #include "test_macros.h"
1116 """.format(script_name
=script_name
,
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
:
1127 Produce documentation for the feature test macros
1130 def make_widths(grid
):
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
]
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)]
1142 for row_i
in range(0, len(grid
)):
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:
1149 separator
= indent_str
+ add_divider(col_widths
, 1 if is_cxx_header
else header_flag
)
1150 result
.append(separator
.rstrip())
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
])
1160 return ' '.join(['-'*w
for w
in widths
])
1162 def pad_cell(s
, length
, left_align
=True):
1163 padding
= ((length
- len(s
)) * ' ')
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():
1174 value
= "``%sL``" % tc
["values"][std
]
1175 if 'unimplemented' in tc
.keys():
1176 value
= '*unimplemented*'
1177 table
+= [["``%s``" % tc
["name"], value
]]
1181 doc_str
= """.. _FeatureTestMacroTable:
1183 ==========================
1184 Feature Test Macro Support
1185 ==========================
1193 This file documents the feature test macros currently supported by libc++.
1200 .. table:: Current Status
1201 :name: feature-status-table
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
:
1213 produce_version_header()
1218 if __name__
== '__main__':