Skip to content

Commit fbd92d0

Browse files
authored
[libc++][format] Disables the FTM on older MacOS versions. (llvm#126547)
On older MacOS versions where `std::to_chars` for floating-point types is not available the format library can't be used. Due to some issue with the availability macro used to disable format on MacOS the issue triggers regardless of the type being formatted. The print library has the same issue. Fixes: llvm#125353
1 parent 4d2d0af commit fbd92d0

File tree

6 files changed

+148
-62
lines changed

6 files changed

+148
-62
lines changed

libcxx/include/version

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@ __cpp_lib_void_t 201411L <type_traits>
417417
# define __cpp_lib_erase_if 202002L
418418
# undef __cpp_lib_execution
419419
// # define __cpp_lib_execution 201902L
420-
# define __cpp_lib_format 202110L
420+
# if _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
421+
# define __cpp_lib_format 202110L
422+
# endif
421423
# define __cpp_lib_format_uchar 202311L
422424
# define __cpp_lib_generic_unordered_lookup 201811L
423425
# define __cpp_lib_int_pow2 202002L
@@ -499,7 +501,9 @@ __cpp_lib_void_t 201411L <type_traits>
499501
# undef __cpp_lib_optional
500502
# define __cpp_lib_optional 202110L
501503
# define __cpp_lib_out_ptr 202106L
502-
# define __cpp_lib_print 202207L
504+
# if _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
505+
# define __cpp_lib_print 202207L
506+
# endif
503507
# undef __cpp_lib_ranges
504508
# define __cpp_lib_ranges 202406L
505509
// # define __cpp_lib_ranges_as_const 202207L

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

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,17 @@
6868

6969
#elif TEST_STD_VER == 20
7070

71-
# ifndef __cpp_lib_format
72-
# error "__cpp_lib_format should be defined in c++20"
73-
# endif
74-
# if __cpp_lib_format != 202110L
75-
# error "__cpp_lib_format should have the value 202110L in c++20"
71+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
72+
# ifndef __cpp_lib_format
73+
# error "__cpp_lib_format should be defined in c++20"
74+
# endif
75+
# if __cpp_lib_format != 202110L
76+
# error "__cpp_lib_format should have the value 202110L in c++20"
77+
# endif
78+
# else
79+
# ifdef __cpp_lib_format
80+
# error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
81+
# endif
7682
# endif
7783

7884
# ifdef __cpp_lib_format_ranges
@@ -88,11 +94,17 @@
8894

8995
#elif TEST_STD_VER == 23
9096

91-
# ifndef __cpp_lib_format
92-
# error "__cpp_lib_format should be defined in c++23"
93-
# endif
94-
# if __cpp_lib_format != 202110L
95-
# error "__cpp_lib_format should have the value 202110L in c++23"
97+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
98+
# ifndef __cpp_lib_format
99+
# error "__cpp_lib_format should be defined in c++23"
100+
# endif
101+
# if __cpp_lib_format != 202110L
102+
# error "__cpp_lib_format should have the value 202110L in c++23"
103+
# endif
104+
# else
105+
# ifdef __cpp_lib_format
106+
# error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
107+
# endif
96108
# endif
97109

98110
# ifndef __cpp_lib_format_ranges
@@ -111,11 +123,17 @@
111123

112124
#elif TEST_STD_VER > 23
113125

114-
# ifndef __cpp_lib_format
115-
# error "__cpp_lib_format should be defined in c++26"
116-
# endif
117-
# if __cpp_lib_format != 202110L
118-
# error "__cpp_lib_format should have the value 202110L in c++26"
126+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
127+
# ifndef __cpp_lib_format
128+
# error "__cpp_lib_format should be defined in c++26"
129+
# endif
130+
# if __cpp_lib_format != 202110L
131+
# error "__cpp_lib_format should have the value 202110L in c++26"
132+
# endif
133+
# else
134+
# ifdef __cpp_lib_format
135+
# error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
136+
# endif
119137
# endif
120138

121139
# ifndef __cpp_lib_format_ranges

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,17 @@
8989
# endif
9090
# endif
9191

92-
# ifndef __cpp_lib_print
93-
# error "__cpp_lib_print should be defined in c++23"
94-
# endif
95-
# if __cpp_lib_print != 202207L
96-
# error "__cpp_lib_print should have the value 202207L in c++23"
92+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
93+
# ifndef __cpp_lib_print
94+
# error "__cpp_lib_print should be defined in c++23"
95+
# endif
96+
# if __cpp_lib_print != 202207L
97+
# error "__cpp_lib_print should have the value 202207L in c++23"
98+
# endif
99+
# else
100+
# ifdef __cpp_lib_print
101+
# error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
102+
# endif
97103
# endif
98104

99105
#elif TEST_STD_VER > 23
@@ -111,11 +117,17 @@
111117
# endif
112118
# endif
113119

114-
# ifndef __cpp_lib_print
115-
# error "__cpp_lib_print should be defined in c++26"
116-
# endif
117-
# if __cpp_lib_print != 202207L
118-
# error "__cpp_lib_print should have the value 202207L in c++26"
120+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
121+
# ifndef __cpp_lib_print
122+
# error "__cpp_lib_print should be defined in c++26"
123+
# endif
124+
# if __cpp_lib_print != 202207L
125+
# error "__cpp_lib_print should have the value 202207L in c++26"
126+
# endif
127+
# else
128+
# ifdef __cpp_lib_print
129+
# error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
130+
# endif
119131
# endif
120132

121133
#endif // TEST_STD_VER > 23

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,32 @@
5050

5151
#elif TEST_STD_VER == 23
5252

53-
# ifndef __cpp_lib_print
54-
# error "__cpp_lib_print should be defined in c++23"
55-
# endif
56-
# if __cpp_lib_print != 202207L
57-
# error "__cpp_lib_print should have the value 202207L in c++23"
53+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
54+
# ifndef __cpp_lib_print
55+
# error "__cpp_lib_print should be defined in c++23"
56+
# endif
57+
# if __cpp_lib_print != 202207L
58+
# error "__cpp_lib_print should have the value 202207L in c++23"
59+
# endif
60+
# else
61+
# ifdef __cpp_lib_print
62+
# error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
63+
# endif
5864
# endif
5965

6066
#elif TEST_STD_VER > 23
6167

62-
# ifndef __cpp_lib_print
63-
# error "__cpp_lib_print should be defined in c++26"
64-
# endif
65-
# if __cpp_lib_print != 202207L
66-
# error "__cpp_lib_print should have the value 202207L in c++26"
68+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
69+
# ifndef __cpp_lib_print
70+
# error "__cpp_lib_print should be defined in c++26"
71+
# endif
72+
# if __cpp_lib_print != 202207L
73+
# error "__cpp_lib_print should have the value 202207L in c++26"
74+
# endif
75+
# else
76+
# ifdef __cpp_lib_print
77+
# error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
78+
# endif
6779
# endif
6880

6981
#endif // TEST_STD_VER > 23

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

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,11 +3685,17 @@
36853685
# error "__cpp_lib_flat_set should not be defined before c++23"
36863686
# endif
36873687

3688-
# ifndef __cpp_lib_format
3689-
# error "__cpp_lib_format should be defined in c++20"
3690-
# endif
3691-
# if __cpp_lib_format != 202110L
3692-
# error "__cpp_lib_format should have the value 202110L in c++20"
3688+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
3689+
# ifndef __cpp_lib_format
3690+
# error "__cpp_lib_format should be defined in c++20"
3691+
# endif
3692+
# if __cpp_lib_format != 202110L
3693+
# error "__cpp_lib_format should have the value 202110L in c++20"
3694+
# endif
3695+
# else
3696+
# ifdef __cpp_lib_format
3697+
# error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
3698+
# endif
36933699
# endif
36943700

36953701
# ifdef __cpp_lib_format_path
@@ -5146,11 +5152,17 @@
51465152
# endif
51475153
# endif
51485154

5149-
# ifndef __cpp_lib_format
5150-
# error "__cpp_lib_format should be defined in c++23"
5151-
# endif
5152-
# if __cpp_lib_format != 202110L
5153-
# error "__cpp_lib_format should have the value 202110L in c++23"
5155+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
5156+
# ifndef __cpp_lib_format
5157+
# error "__cpp_lib_format should be defined in c++23"
5158+
# endif
5159+
# if __cpp_lib_format != 202110L
5160+
# error "__cpp_lib_format should have the value 202110L in c++23"
5161+
# endif
5162+
# else
5163+
# ifdef __cpp_lib_format
5164+
# error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
5165+
# endif
51545166
# endif
51555167

51565168
# ifdef __cpp_lib_format_path
@@ -5679,11 +5691,17 @@
56795691
# endif
56805692
# endif
56815693

5682-
# ifndef __cpp_lib_print
5683-
# error "__cpp_lib_print should be defined in c++23"
5684-
# endif
5685-
# if __cpp_lib_print != 202207L
5686-
# error "__cpp_lib_print should have the value 202207L in c++23"
5694+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
5695+
# ifndef __cpp_lib_print
5696+
# error "__cpp_lib_print should be defined in c++23"
5697+
# endif
5698+
# if __cpp_lib_print != 202207L
5699+
# error "__cpp_lib_print should have the value 202207L in c++23"
5700+
# endif
5701+
# else
5702+
# ifdef __cpp_lib_print
5703+
# error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
5704+
# endif
56875705
# endif
56885706

56895707
# if !defined(_LIBCPP_VERSION) || _LIBCPP_HAS_LOCALIZATION
@@ -6853,11 +6871,17 @@
68536871
# endif
68546872
# endif
68556873

6856-
# ifndef __cpp_lib_format
6857-
# error "__cpp_lib_format should be defined in c++26"
6858-
# endif
6859-
# if __cpp_lib_format != 202110L
6860-
# error "__cpp_lib_format should have the value 202110L in c++26"
6874+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
6875+
# ifndef __cpp_lib_format
6876+
# error "__cpp_lib_format should be defined in c++26"
6877+
# endif
6878+
# if __cpp_lib_format != 202110L
6879+
# error "__cpp_lib_format should have the value 202110L in c++26"
6880+
# endif
6881+
# else
6882+
# ifdef __cpp_lib_format
6883+
# error "__cpp_lib_format should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
6884+
# endif
68616885
# endif
68626886

68636887
# if !defined(_LIBCPP_VERSION)
@@ -7557,11 +7581,17 @@
75577581
# endif
75587582
# endif
75597583

7560-
# ifndef __cpp_lib_print
7561-
# error "__cpp_lib_print should be defined in c++26"
7562-
# endif
7563-
# if __cpp_lib_print != 202207L
7564-
# error "__cpp_lib_print should have the value 202207L in c++26"
7584+
# if !defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT
7585+
# ifndef __cpp_lib_print
7586+
# error "__cpp_lib_print should be defined in c++26"
7587+
# endif
7588+
# if __cpp_lib_print != 202207L
7589+
# error "__cpp_lib_print should have the value 202207L in c++26"
7590+
# endif
7591+
# else
7592+
# ifdef __cpp_lib_print
7593+
# error "__cpp_lib_print should not be defined when the requirement '!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT' is not met!"
7594+
# endif
75657595
# endif
75667596

75677597
# if !defined(_LIBCPP_VERSION) || _LIBCPP_HAS_LOCALIZATION

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,11 @@ def add_version_header(tc):
536536
# 202305 P2757R3 Type-checking format args
537537
# 202306 P2637R3 Member Visit
538538
"headers": ["format"],
539+
# Trying to use `std::format` where to_chars floating-point is not
540+
# available causes compilation errors, even with non floating-point types.
541+
# https://github.com/llvm/llvm-project/issues/125353
542+
"test_suite_guard": "!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT",
543+
"libcxx_guard": "_LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT",
539544
},
540545
{
541546
"name": "__cpp_lib_format_path",
@@ -1011,6 +1016,11 @@ def add_version_header(tc):
10111016
# "c++26": 202406, # P3235R3 std::print more types faster with less memory
10121017
},
10131018
"headers": ["ostream", "print"],
1019+
# Trying to use `std::print` where to_chars floating-point is not
1020+
# available causes compilation errors, even with non floating-point types.
1021+
# https://github.com/llvm/llvm-project/issues/125353
1022+
"test_suite_guard": "!defined(_LIBCPP_VERSION) || _LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT",
1023+
"libcxx_guard": "_LIBCPP_AVAILABILITY_HAS_TO_CHARS_FLOATING_POINT",
10141024
},
10151025
{
10161026
"name": "__cpp_lib_quoted_string_io",

0 commit comments

Comments
 (0)