Skip to content

Commit 7253396

Browse files
ldionnetstellar
authored andcommitted
[libc++] Add missing conditionals for feature-test macros (llvm#80168)
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)
1 parent 47fbb64 commit 7253396

File tree

7 files changed

+254
-122
lines changed

7 files changed

+254
-122
lines changed

libcxx/include/version

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ __cpp_lib_within_lifetime 202306L <type_traits>
266266
# define __cpp_lib_make_reverse_iterator 201402L
267267
# define __cpp_lib_make_unique 201304L
268268
# define __cpp_lib_null_iterators 201304L
269-
# define __cpp_lib_quoted_string_io 201304L
269+
# if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
270+
# define __cpp_lib_quoted_string_io 201304L
271+
# endif
270272
# define __cpp_lib_result_of_sfinae 201210L
271273
# define __cpp_lib_robust_nonmodifying_seq_ops 201304L
272274
# if !defined(_LIBCPP_HAS_NO_THREADS)
@@ -294,7 +296,7 @@ __cpp_lib_within_lifetime 202306L <type_traits>
294296
# define __cpp_lib_clamp 201603L
295297
# define __cpp_lib_enable_shared_from_this 201603L
296298
// # define __cpp_lib_execution 201603L
297-
# if _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
299+
# if !defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
298300
# define __cpp_lib_filesystem 201703L
299301
# endif
300302
# define __cpp_lib_gcd_lcm 201606L
@@ -323,7 +325,9 @@ __cpp_lib_within_lifetime 202306L <type_traits>
323325
// # define __cpp_lib_parallel_algorithm 201603L
324326
# define __cpp_lib_raw_memory_algorithms 201606L
325327
# define __cpp_lib_sample 201603L
326-
# define __cpp_lib_scoped_lock 201703L
328+
# if !defined(_LIBCPP_HAS_NO_THREADS)
329+
# define __cpp_lib_scoped_lock 201703L
330+
# endif
327331
# if !defined(_LIBCPP_HAS_NO_THREADS)
328332
# define __cpp_lib_shared_mutex 201505L
329333
# endif
@@ -496,7 +500,9 @@ __cpp_lib_within_lifetime 202306L <type_traits>
496500
// # define __cpp_lib_freestanding_optional 202311L
497501
// # define __cpp_lib_freestanding_string_view 202311L
498502
// # define __cpp_lib_freestanding_variant 202311L
499-
# define __cpp_lib_fstream_native_handle 202306L
503+
# if !defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
504+
# define __cpp_lib_fstream_native_handle 202306L
505+
# endif
500506
// # define __cpp_lib_function_ref 202306L
501507
// # define __cpp_lib_hazard_pointer 202306L
502508
// # define __cpp_lib_linalg 202311L

libcxx/test/std/language.support/support.limits/support.limits.general/filesystem.version.compile.pass.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# error "__cpp_lib_char8_t should not be defined before c++20"
5252
# endif
5353

54-
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
54+
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)
5555
# ifndef __cpp_lib_filesystem
5656
# error "__cpp_lib_filesystem should be defined in c++17"
5757
# endif
@@ -60,7 +60,7 @@
6060
# endif
6161
# else
6262
# ifdef __cpp_lib_filesystem
63-
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY' is not met!"
63+
# 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!"
6464
# endif
6565
# endif
6666

@@ -79,7 +79,7 @@
7979
# endif
8080
# endif
8181

82-
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
82+
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)
8383
# ifndef __cpp_lib_filesystem
8484
# error "__cpp_lib_filesystem should be defined in c++20"
8585
# endif
@@ -88,7 +88,7 @@
8888
# endif
8989
# else
9090
# ifdef __cpp_lib_filesystem
91-
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY' is not met!"
91+
# 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!"
9292
# endif
9393
# endif
9494

@@ -107,7 +107,7 @@
107107
# endif
108108
# endif
109109

110-
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
110+
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)
111111
# ifndef __cpp_lib_filesystem
112112
# error "__cpp_lib_filesystem should be defined in c++23"
113113
# endif
@@ -116,7 +116,7 @@
116116
# endif
117117
# else
118118
# ifdef __cpp_lib_filesystem
119-
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY' is not met!"
119+
# 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!"
120120
# endif
121121
# endif
122122

@@ -135,7 +135,7 @@
135135
# endif
136136
# endif
137137

138-
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY
138+
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY)
139139
# ifndef __cpp_lib_filesystem
140140
# error "__cpp_lib_filesystem should be defined in c++26"
141141
# endif
@@ -144,7 +144,7 @@
144144
# endif
145145
# else
146146
# ifdef __cpp_lib_filesystem
147-
# error "__cpp_lib_filesystem should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_FILESYSTEM_LIBRARY' is not met!"
147+
# 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!"
148148
# endif
149149
# endif
150150

libcxx/test/std/language.support/support.limits/support.limits.general/fstream.version.compile.pass.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,17 @@
5656

5757
#elif TEST_STD_VER > 23
5858

59-
# ifndef __cpp_lib_fstream_native_handle
60-
# error "__cpp_lib_fstream_native_handle should be defined in c++26"
61-
# endif
62-
# if __cpp_lib_fstream_native_handle != 202306L
63-
# error "__cpp_lib_fstream_native_handle should have the value 202306L in c++26"
59+
# if !defined(_LIBCPP_VERSION) || (!defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION))
60+
# ifndef __cpp_lib_fstream_native_handle
61+
# error "__cpp_lib_fstream_native_handle should be defined in c++26"
62+
# endif
63+
# if __cpp_lib_fstream_native_handle != 202306L
64+
# error "__cpp_lib_fstream_native_handle should have the value 202306L in c++26"
65+
# endif
66+
# else
67+
# ifdef __cpp_lib_fstream_native_handle
68+
# 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!"
69+
# endif
6470
# endif
6571

6672
#endif // TEST_STD_VER > 23

libcxx/test/std/language.support/support.limits/support.limits.general/iomanip.version.compile.pass.cpp

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,77 @@
3232

3333
#elif TEST_STD_VER == 14
3434

35-
# ifndef __cpp_lib_quoted_string_io
36-
# error "__cpp_lib_quoted_string_io should be defined in c++14"
37-
# endif
38-
# if __cpp_lib_quoted_string_io != 201304L
39-
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++14"
35+
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
36+
# ifndef __cpp_lib_quoted_string_io
37+
# error "__cpp_lib_quoted_string_io should be defined in c++14"
38+
# endif
39+
# if __cpp_lib_quoted_string_io != 201304L
40+
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++14"
41+
# endif
42+
# else
43+
# ifdef __cpp_lib_quoted_string_io
44+
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
45+
# endif
4046
# endif
4147

4248
#elif TEST_STD_VER == 17
4349

44-
# ifndef __cpp_lib_quoted_string_io
45-
# error "__cpp_lib_quoted_string_io should be defined in c++17"
46-
# endif
47-
# if __cpp_lib_quoted_string_io != 201304L
48-
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++17"
50+
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
51+
# ifndef __cpp_lib_quoted_string_io
52+
# error "__cpp_lib_quoted_string_io should be defined in c++17"
53+
# endif
54+
# if __cpp_lib_quoted_string_io != 201304L
55+
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++17"
56+
# endif
57+
# else
58+
# ifdef __cpp_lib_quoted_string_io
59+
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
60+
# endif
4961
# endif
5062

5163
#elif TEST_STD_VER == 20
5264

53-
# ifndef __cpp_lib_quoted_string_io
54-
# error "__cpp_lib_quoted_string_io should be defined in c++20"
55-
# endif
56-
# if __cpp_lib_quoted_string_io != 201304L
57-
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++20"
65+
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
66+
# ifndef __cpp_lib_quoted_string_io
67+
# error "__cpp_lib_quoted_string_io should be defined in c++20"
68+
# endif
69+
# if __cpp_lib_quoted_string_io != 201304L
70+
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++20"
71+
# endif
72+
# else
73+
# ifdef __cpp_lib_quoted_string_io
74+
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
75+
# endif
5876
# endif
5977

6078
#elif TEST_STD_VER == 23
6179

62-
# ifndef __cpp_lib_quoted_string_io
63-
# error "__cpp_lib_quoted_string_io should be defined in c++23"
64-
# endif
65-
# if __cpp_lib_quoted_string_io != 201304L
66-
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++23"
80+
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
81+
# ifndef __cpp_lib_quoted_string_io
82+
# error "__cpp_lib_quoted_string_io should be defined in c++23"
83+
# endif
84+
# if __cpp_lib_quoted_string_io != 201304L
85+
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++23"
86+
# endif
87+
# else
88+
# ifdef __cpp_lib_quoted_string_io
89+
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
90+
# endif
6791
# endif
6892

6993
#elif TEST_STD_VER > 23
7094

71-
# ifndef __cpp_lib_quoted_string_io
72-
# error "__cpp_lib_quoted_string_io should be defined in c++26"
73-
# endif
74-
# if __cpp_lib_quoted_string_io != 201304L
75-
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++26"
95+
# if !defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)
96+
# ifndef __cpp_lib_quoted_string_io
97+
# error "__cpp_lib_quoted_string_io should be defined in c++26"
98+
# endif
99+
# if __cpp_lib_quoted_string_io != 201304L
100+
# error "__cpp_lib_quoted_string_io should have the value 201304L in c++26"
101+
# endif
102+
# else
103+
# ifdef __cpp_lib_quoted_string_io
104+
# error "__cpp_lib_quoted_string_io should not be defined when the requirement '!defined(_LIBCPP_VERSION) || !defined(_LIBCPP_HAS_NO_LOCALIZATION)' is not met!"
105+
# endif
76106
# endif
77107

78108
#endif // TEST_STD_VER > 23

libcxx/test/std/language.support/support.limits/support.limits.general/mutex.version.compile.pass.cpp

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,62 @@
3838

3939
#elif TEST_STD_VER == 17
4040

41-
# ifndef __cpp_lib_scoped_lock
42-
# error "__cpp_lib_scoped_lock should be defined in c++17"
43-
# endif
44-
# if __cpp_lib_scoped_lock != 201703L
45-
# error "__cpp_lib_scoped_lock should have the value 201703L in c++17"
41+
# if !defined(_LIBCPP_HAS_NO_THREADS)
42+
# ifndef __cpp_lib_scoped_lock
43+
# error "__cpp_lib_scoped_lock should be defined in c++17"
44+
# endif
45+
# if __cpp_lib_scoped_lock != 201703L
46+
# error "__cpp_lib_scoped_lock should have the value 201703L in c++17"
47+
# endif
48+
# else
49+
# ifdef __cpp_lib_scoped_lock
50+
# error "__cpp_lib_scoped_lock should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS)' is not met!"
51+
# endif
4652
# endif
4753

4854
#elif TEST_STD_VER == 20
4955

50-
# ifndef __cpp_lib_scoped_lock
51-
# error "__cpp_lib_scoped_lock should be defined in c++20"
52-
# endif
53-
# if __cpp_lib_scoped_lock != 201703L
54-
# error "__cpp_lib_scoped_lock should have the value 201703L in c++20"
56+
# if !defined(_LIBCPP_HAS_NO_THREADS)
57+
# ifndef __cpp_lib_scoped_lock
58+
# error "__cpp_lib_scoped_lock should be defined in c++20"
59+
# endif
60+
# if __cpp_lib_scoped_lock != 201703L
61+
# error "__cpp_lib_scoped_lock should have the value 201703L in c++20"
62+
# endif
63+
# else
64+
# ifdef __cpp_lib_scoped_lock
65+
# error "__cpp_lib_scoped_lock should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS)' is not met!"
66+
# endif
5567
# endif
5668

5769
#elif TEST_STD_VER == 23
5870

59-
# ifndef __cpp_lib_scoped_lock
60-
# error "__cpp_lib_scoped_lock should be defined in c++23"
61-
# endif
62-
# if __cpp_lib_scoped_lock != 201703L
63-
# error "__cpp_lib_scoped_lock should have the value 201703L in c++23"
71+
# if !defined(_LIBCPP_HAS_NO_THREADS)
72+
# ifndef __cpp_lib_scoped_lock
73+
# error "__cpp_lib_scoped_lock should be defined in c++23"
74+
# endif
75+
# if __cpp_lib_scoped_lock != 201703L
76+
# error "__cpp_lib_scoped_lock should have the value 201703L in c++23"
77+
# endif
78+
# else
79+
# ifdef __cpp_lib_scoped_lock
80+
# error "__cpp_lib_scoped_lock should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS)' is not met!"
81+
# endif
6482
# endif
6583

6684
#elif TEST_STD_VER > 23
6785

68-
# ifndef __cpp_lib_scoped_lock
69-
# error "__cpp_lib_scoped_lock should be defined in c++26"
70-
# endif
71-
# if __cpp_lib_scoped_lock != 201703L
72-
# error "__cpp_lib_scoped_lock should have the value 201703L in c++26"
86+
# if !defined(_LIBCPP_HAS_NO_THREADS)
87+
# ifndef __cpp_lib_scoped_lock
88+
# error "__cpp_lib_scoped_lock should be defined in c++26"
89+
# endif
90+
# if __cpp_lib_scoped_lock != 201703L
91+
# error "__cpp_lib_scoped_lock should have the value 201703L in c++26"
92+
# endif
93+
# else
94+
# ifdef __cpp_lib_scoped_lock
95+
# error "__cpp_lib_scoped_lock should not be defined when the requirement '!defined(_LIBCPP_HAS_NO_THREADS)' is not met!"
96+
# endif
7397
# endif
7498

7599
#endif // TEST_STD_VER > 23

0 commit comments

Comments
 (0)