Skip to content

Commit

Permalink
[libc++] Add missing conditionals for feature-test macros (#80168)
Browse files Browse the repository at this point in the history
We noticed that some feature-test macros were not conditional on
configuration flags like _LIBCPP_HAS_NO_FILESYSTEM. As a result, code
attempting to use FTMs would not work as intended.

This patch adds conditionals for a few feature-test macros, but more
issues may exist.

rdar://122020466
(cherry picked from commit f2c8421)
  • Loading branch information
ldionne authored and tstellar committed Feb 5, 2024
1 parent 47fbb64 commit 7253396
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 122 deletions.
14 changes: 10 additions & 4 deletions libcxx/include/version
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ __cpp_lib_within_lifetime 202306L <type_traits>
# define __cpp_lib_make_reverse_iterator 201402L
# define __cpp_lib_make_unique 201304L
# define __cpp_lib_null_iterators 201304L
# define __cpp_lib_quoted_string_io 201304L
# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# define __cpp_lib_quoted_string_io 201304L
# endif
# define __cpp_lib_result_of_sfinae 201210L
# define __cpp_lib_robust_nonmodifying_seq_ops 201304L
# if !defined(_LIBCPP_HAS_NO_THREADS)
Expand Down Expand Up @@ -294,7 +296,7 @@ __cpp_lib_within_lifetime 202306L <type_traits>
# define __cpp_lib_clamp 201603L
# define __cpp_lib_enable_shared_from_this 201603L
// # define __cpp_lib_execution 201603L
# if _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
# if !defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
# define __cpp_lib_filesystem 201703L
# endif
# define __cpp_lib_gcd_lcm 201606L
Expand Down Expand Up @@ -323,7 +325,9 @@ __cpp_lib_within_lifetime 202306L <type_traits>
// # define __cpp_lib_parallel_algorithm 201603L
# define __cpp_lib_raw_memory_algorithms 201606L
# define __cpp_lib_sample 201603L
# define __cpp_lib_scoped_lock 201703L
# if !defined(_LIBCPP_HAS_NO_THREADS)
# define __cpp_lib_scoped_lock 201703L
# endif
# if !defined(_LIBCPP_HAS_NO_THREADS)
# define __cpp_lib_shared_mutex 201505L
# endif
Expand Down Expand Up @@ -496,7 +500,9 @@ __cpp_lib_within_lifetime 202306L <type_traits>
// # define __cpp_lib_freestanding_optional 202311L
// # define __cpp_lib_freestanding_string_view 202311L
// # define __cpp_lib_freestanding_variant 202311L
# define __cpp_lib_fstream_native_handle 202306L
# if !defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# define __cpp_lib_fstream_native_handle 202306L
# endif
// # define __cpp_lib_function_ref 202306L
// # define __cpp_lib_hazard_pointer 202306L
// # define __cpp_lib_linalg 202311L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
# error "__cpp_lib_char8_t should not be defined before c++20"
# endif

# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)
# ifndef __cpp_lib_filesystem
# error "__cpp_lib_filesystem should be defined in c++17"
# endif
Expand All @@ -60,7 +60,7 @@
# endif
# else
# ifdef __cpp_lib_filesystem
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY' is not met!"
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)' is not met!"
# endif
# endif

Expand All @@ -79,7 +79,7 @@
# endif
# endif

# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)
# ifndef __cpp_lib_filesystem
# error "__cpp_lib_filesystem should be defined in c++20"
# endif
Expand All @@ -88,7 +88,7 @@
# endif
# else
# ifdef __cpp_lib_filesystem
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY' is not met!"
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)' is not met!"
# endif
# endif

Expand All @@ -107,7 +107,7 @@
# endif
# endif

# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)
# ifndef __cpp_lib_filesystem
# error "__cpp_lib_filesystem should be defined in c++23"
# endif
Expand All @@ -116,7 +116,7 @@
# endif
# else
# ifdef __cpp_lib_filesystem
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY' is not met!"
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)' is not met!"
# endif
# endif

Expand All @@ -135,7 +135,7 @@
# endif
# endif

# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)
# ifndef __cpp_lib_filesystem
# error "__cpp_lib_filesystem should be defined in c++26"
# endif
Expand All @@ -144,7 +144,7 @@
# endif
# else
# ifdef __cpp_lib_filesystem
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY' is not met!"
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)' is not met!"
# endif
# endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@

#elif TEST_STD_VER > 23

# ifndef __cpp_lib_fstream_native_handle
# error "__cpp_lib_fstream_native_handle should be defined in c++26"
# endif
# if __cpp_lib_fstream_native_handle != 202306L
# error "__cpp_lib_fstream_native_handle should have the value 202306L in c++26"
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION))
# ifndef __cpp_lib_fstream_native_handle
# error "__cpp_lib_fstream_native_handle should be defined in c++26"
# endif
# if __cpp_lib_fstream_native_handle != 202306L
# error "__cpp_lib_fstream_native_handle should have the value 202306L in c++26"
# endif
# else
# ifdef __cpp_lib_fstream_native_handle
# error "__cpp_lib_fstream_native_handle should not be defined when the requirement '!defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION))' is not met!"
# endif
# endif

#endif // TEST_STD_VER > 23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,77 @@

#elif TEST_STD_VER == 14

# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++14"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++14"
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++14"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++14"
# endif
# else
# ifdef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
# endif
# endif

#elif TEST_STD_VER == 17

# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++17"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++17"
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++17"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++17"
# endif
# else
# ifdef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
# endif
# endif

#elif TEST_STD_VER == 20

# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++20"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++20"
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++20"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++20"
# endif
# else
# ifdef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
# endif
# endif

#elif TEST_STD_VER == 23

# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++23"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++23"
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++23"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++23"
# endif
# else
# ifdef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
# endif
# endif

#elif TEST_STD_VER > 23

# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++26"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++26"
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# ifndef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should be defined in c++26"
# endif
# if __cpp_lib_quoted_string_io != 201304L
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++26"
# endif
# else
# ifdef __cpp_lib_quoted_string_io
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
# endif
# endif

#endif // TEST_STD_VER > 23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,62 @@

#elif TEST_STD_VER == 17

# ifndef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should be defined in c++17"
# endif
# if __cpp_lib_scoped_lock != 201703L
# error "__cpp_lib_scoped_lock should have the value 201703L in c++17"
# if !defined(_LIBCPP_HAS_NO_THREADS)
# ifndef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should be defined in c++17"
# endif
# if __cpp_lib_scoped_lock != 201703L
# error "__cpp_lib_scoped_lock should have the value 201703L in c++17"
# endif
# else
# ifdef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS)' is not met!"
# endif
# endif

#elif TEST_STD_VER == 20

# ifndef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should be defined in c++20"
# endif
# if __cpp_lib_scoped_lock != 201703L
# error "__cpp_lib_scoped_lock should have the value 201703L in c++20"
# if !defined(_LIBCPP_HAS_NO_THREADS)
# ifndef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should be defined in c++20"
# endif
# if __cpp_lib_scoped_lock != 201703L
# error "__cpp_lib_scoped_lock should have the value 201703L in c++20"
# endif
# else
# ifdef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS)' is not met!"
# endif
# endif

#elif TEST_STD_VER == 23

# ifndef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should be defined in c++23"
# endif
# if __cpp_lib_scoped_lock != 201703L
# error "__cpp_lib_scoped_lock should have the value 201703L in c++23"
# if !defined(_LIBCPP_HAS_NO_THREADS)
# ifndef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should be defined in c++23"
# endif
# if __cpp_lib_scoped_lock != 201703L
# error "__cpp_lib_scoped_lock should have the value 201703L in c++23"
# endif
# else
# ifdef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS)' is not met!"
# endif
# endif

#elif TEST_STD_VER > 23

# ifndef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should be defined in c++26"
# endif
# if __cpp_lib_scoped_lock != 201703L
# error "__cpp_lib_scoped_lock should have the value 201703L in c++26"
# if !defined(_LIBCPP_HAS_NO_THREADS)
# ifndef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should be defined in c++26"
# endif
# if __cpp_lib_scoped_lock != 201703L
# error "__cpp_lib_scoped_lock should have the value 201703L in c++26"
# endif
# else
# ifdef __cpp_lib_scoped_lock
# error "__cpp_lib_scoped_lock should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS)' is not met!"
# endif
# endif

#endif // TEST_STD_VER > 23
Expand Down

0 comments on commit 7253396

Please sign in to comment.