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