Skip to content

Commit cae351f

Browse files
[libc++] Bump __cpp_lib_optional and __cpp_lib_variant (#113650)
In C++20 mode, `__cpp_lib_optional` and `__cpp_lib_variant` should be `202106L` due to DR P2231R1. In C++26 mode, `__cpp_lib_variant` should be bumped to `202306L` due to P2637R3. - Clang 16/17 shouldn't get this bumping (as member `visit` requires explicit object parameters), but it's very tricky to make the bumping conditionally enabled. I _hope_ unconditionally bumping in C++26 will be OK for LLVM 20 when the support for Clang 17 is dropped. Related PRs: - https://reviews.llvm.org/D102119 - #83335 - #76447
1 parent 5ad500c commit cae351f

File tree

8 files changed

+47
-22
lines changed

8 files changed

+47
-22
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ Status
264264
---------------------------------------------------------- -----------------
265265
``__cpp_lib_move_iterator_concept`` ``202207L``
266266
---------------------------------------------------------- -----------------
267+
``__cpp_lib_optional`` ``202106L``
268+
---------------------------------------------------------- -----------------
267269
``__cpp_lib_polymorphic_allocator`` ``201902L``
268270
---------------------------------------------------------- -----------------
269271
``__cpp_lib_ranges`` ``202110L``
@@ -300,6 +302,8 @@ Status
300302
---------------------------------------------------------- -----------------
301303
``__cpp_lib_unwrap_ref`` ``201811L``
302304
---------------------------------------------------------- -----------------
305+
``__cpp_lib_variant`` ``202106L``
306+
---------------------------------------------------------- -----------------
303307
**C++23**
304308
----------------------------------------------------------------------------
305309
``__cpp_lib_adaptor_iterator_pair_constructor`` ``202106L``
@@ -491,5 +495,7 @@ Status
491495
``__cpp_lib_to_string`` *unimplemented*
492496
---------------------------------------------------------- -----------------
493497
``__cpp_lib_tuple_like`` *unimplemented*
498+
---------------------------------------------------------- -----------------
499+
``__cpp_lib_variant`` ``202306L``
494500
========================================================== =================
495501

libcxx/docs/Status/Cxx20Papers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"`P2106R0 <https://wg21.link/P2106R0>`__","Alternative wording for GB315 and GB316","2020-02 (Prague)","|Complete|","15.0",""
193193
"`P2116R0 <https://wg21.link/P2116R0>`__","Remove tuple-like protocol support from fixed-extent span","2020-02 (Prague)","|Complete|","11.0",""
194194
"","","","","",""
195-
"`P2231R1 <https://wg21.link/P2231R1>`__","Missing constexpr in std::optional and std::variant","2021-06 (Virtual)","|Complete|","19.0",""
195+
"`P2231R1 <https://wg21.link/P2231R1>`__","Missing constexpr in std::optional and std::variant","2021-06 (Virtual)","|Complete|","19.0","Changes of feature-test macros are completed in LLVM 20."
196196
"`P2325R3 <https://wg21.link/P2325R3>`__","Views should not be required to be default constructible","2021-06 (Virtual)","|Complete|","16.0",""
197197
"`P2210R2 <https://wg21.link/P2210R2>`__","Superior String Splitting","2021-06 (Virtual)","|Complete|","16.0",""
198198
"`P2216R3 <https://wg21.link/P2216R3>`__","std::format improvements","2021-06 (Virtual)","|Complete|","15.0",""

libcxx/docs/Status/Cxx2cPapers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"`P0792R14 <https://wg21.link/P0792R14>`__","``function_ref``: a type-erased callable reference","2023-06 (Varna)","","",""
1818
"`P2874R2 <https://wg21.link/P2874R2>`__","Mandating Annex D Require No More","2023-06 (Varna)","","",""
1919
"`P2757R3 <https://wg21.link/P2757R3>`__","Type-checking format args","2023-06 (Varna)","","",""
20-
"`P2637R3 <https://wg21.link/P2637R3>`__","Member ``visit``","2023-06 (Varna)","|Complete|","19.0",""
20+
"`P2637R3 <https://wg21.link/P2637R3>`__","Member ``visit``","2023-06 (Varna)","|Complete|","19.0","Change of ``__cpp_lib_variant`` is completed in LLVM 20. Change of ``__cpp_lib_format`` is blocked by `P2419R2 <https://wg21.link/P2419R2>`__."
2121
"`P2641R4 <https://wg21.link/P2641R4>`__","Checking if a ``union`` alternative is active","2023-06 (Varna)","","",""
2222
"`P1759R6 <https://wg21.link/P1759R6>`__","Native handles and file streams","2023-06 (Varna)","|Complete|","18.0",""
2323
"`P2697R1 <https://wg21.link/P2697R1>`__","Interfacing ``bitset`` with ``string_view``","2023-06 (Varna)","|Complete|","18.0",""

libcxx/include/version

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ __cpp_lib_nonmember_container_access 201411L <array> <deque>
174174
__cpp_lib_not_fn 201603L <functional>
175175
__cpp_lib_null_iterators 201304L <iterator>
176176
__cpp_lib_optional 202110L <optional>
177+
202106L // C++20
177178
201606L // C++17
178179
__cpp_lib_optional_range_support 202406L <optional>
179180
__cpp_lib_out_ptr 202311L <memory>
@@ -261,7 +262,9 @@ __cpp_lib_uncaught_exceptions 201411L <exception>
261262
__cpp_lib_unordered_map_try_emplace 201411L <unordered_map>
262263
__cpp_lib_unreachable 202202L <utility>
263264
__cpp_lib_unwrap_ref 201811L <functional>
264-
__cpp_lib_variant 202102L <variant>
265+
__cpp_lib_variant 202306L <variant>
266+
202106L // C++20
267+
202102L // C++17
265268
__cpp_lib_void_t 201411L <type_traits>
266269
267270
*/
@@ -427,6 +430,8 @@ __cpp_lib_void_t 201411L <type_traits>
427430
# define __cpp_lib_list_remove_return_type 201806L
428431
# define __cpp_lib_math_constants 201907L
429432
# define __cpp_lib_move_iterator_concept 202207L
433+
# undef __cpp_lib_optional
434+
# define __cpp_lib_optional 202106L
430435
# if _LIBCPP_AVAILABILITY_HAS_PMR
431436
# define __cpp_lib_polymorphic_allocator 201902L
432437
# endif
@@ -453,6 +458,8 @@ __cpp_lib_void_t 201411L <type_traits>
453458
# define __cpp_lib_to_array 201907L
454459
# define __cpp_lib_type_identity 201806L
455460
# define __cpp_lib_unwrap_ref 201811L
461+
# undef __cpp_lib_variant
462+
# define __cpp_lib_variant 202106L
456463
#endif
457464

458465
#if _LIBCPP_STD_VER >= 23
@@ -570,6 +577,8 @@ __cpp_lib_void_t 201411L <type_traits>
570577
// # define __cpp_lib_to_string 202306L
571578
# undef __cpp_lib_tuple_like
572579
// # define __cpp_lib_tuple_like 202311L
580+
# undef __cpp_lib_variant
581+
# define __cpp_lib_variant 202306L
573582
#endif
574583

575584
// clang-format on

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
__cpp_lib_constrained_equality 202403L [C++26]
2020
__cpp_lib_freestanding_optional 202311L [C++26]
2121
__cpp_lib_optional 201606L [C++17]
22+
202106L [C++20]
2223
202110L [C++23]
2324
__cpp_lib_optional_range_support 202406L [C++26]
2425
*/
@@ -96,8 +97,8 @@
9697
# ifndef __cpp_lib_optional
9798
# error "__cpp_lib_optional should be defined in c++20"
9899
# endif
99-
# if __cpp_lib_optional != 201606L
100-
# error "__cpp_lib_optional should have the value 201606L in c++20"
100+
# if __cpp_lib_optional != 202106L
101+
# error "__cpp_lib_optional should have the value 202106L in c++20"
101102
# endif
102103

103104
# ifdef __cpp_lib_optional_range_support

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
__cpp_lib_constrained_equality 202403L [C++26]
2020
__cpp_lib_freestanding_variant 202311L [C++26]
2121
__cpp_lib_variant 202102L [C++17]
22+
202106L [C++20]
23+
202306L [C++26]
2224
*/
2325

2426
#include <variant>
@@ -82,8 +84,8 @@
8284
# ifndef __cpp_lib_variant
8385
# error "__cpp_lib_variant should be defined in c++20"
8486
# endif
85-
# if __cpp_lib_variant != 202102L
86-
# error "__cpp_lib_variant should have the value 202102L in c++20"
87+
# if __cpp_lib_variant != 202106L
88+
# error "__cpp_lib_variant should have the value 202106L in c++20"
8789
# endif
8890

8991
#elif TEST_STD_VER == 23
@@ -99,8 +101,8 @@
99101
# ifndef __cpp_lib_variant
100102
# error "__cpp_lib_variant should be defined in c++23"
101103
# endif
102-
# if __cpp_lib_variant != 202102L
103-
# error "__cpp_lib_variant should have the value 202102L in c++23"
104+
# if __cpp_lib_variant != 202106L
105+
# error "__cpp_lib_variant should have the value 202106L in c++23"
104106
# endif
105107

106108
#elif TEST_STD_VER > 23
@@ -134,8 +136,8 @@
134136
# ifndef __cpp_lib_variant
135137
# error "__cpp_lib_variant should be defined in c++26"
136138
# endif
137-
# if __cpp_lib_variant != 202102L
138-
# error "__cpp_lib_variant should have the value 202102L in c++26"
139+
# if __cpp_lib_variant != 202306L
140+
# error "__cpp_lib_variant should have the value 202306L in c++26"
139141
# endif
140142

141143
#endif // TEST_STD_VER > 23

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
__cpp_lib_not_fn 201603L [C++17]
159159
__cpp_lib_null_iterators 201304L [C++14]
160160
__cpp_lib_optional 201606L [C++17]
161+
202106L [C++20]
161162
202110L [C++23]
162163
__cpp_lib_optional_range_support 202406L [C++26]
163164
__cpp_lib_out_ptr 202106L [C++23]
@@ -244,6 +245,8 @@
244245
__cpp_lib_unreachable 202202L [C++23]
245246
__cpp_lib_unwrap_ref 201811L [C++20]
246247
__cpp_lib_variant 202102L [C++17]
248+
202106L [C++20]
249+
202306L [C++26]
247250
__cpp_lib_void_t 201411L [C++17]
248251
*/
249252

@@ -4087,8 +4090,8 @@
40874090
# ifndef __cpp_lib_optional
40884091
# error "__cpp_lib_optional should be defined in c++20"
40894092
# endif
4090-
# if __cpp_lib_optional != 201606L
4091-
# error "__cpp_lib_optional should have the value 201606L in c++20"
4093+
# if __cpp_lib_optional != 202106L
4094+
# error "__cpp_lib_optional should have the value 202106L in c++20"
40924095
# endif
40934096

40944097
# ifdef __cpp_lib_optional_range_support
@@ -4569,8 +4572,8 @@
45694572
# ifndef __cpp_lib_variant
45704573
# error "__cpp_lib_variant should be defined in c++20"
45714574
# endif
4572-
# if __cpp_lib_variant != 202102L
4573-
# error "__cpp_lib_variant should have the value 202102L in c++20"
4575+
# if __cpp_lib_variant != 202106L
4576+
# error "__cpp_lib_variant should have the value 202106L in c++20"
45744577
# endif
45754578

45764579
# ifndef __cpp_lib_void_t
@@ -6196,8 +6199,8 @@
61966199
# ifndef __cpp_lib_variant
61976200
# error "__cpp_lib_variant should be defined in c++23"
61986201
# endif
6199-
# if __cpp_lib_variant != 202102L
6200-
# error "__cpp_lib_variant should have the value 202102L in c++23"
6202+
# if __cpp_lib_variant != 202106L
6203+
# error "__cpp_lib_variant should have the value 202106L in c++23"
62016204
# endif
62026205

62036206
# ifndef __cpp_lib_void_t
@@ -8141,8 +8144,8 @@
81418144
# ifndef __cpp_lib_variant
81428145
# error "__cpp_lib_variant should be defined in c++26"
81438146
# endif
8144-
# if __cpp_lib_variant != 202102L
8145-
# error "__cpp_lib_variant should have the value 202102L in c++26"
8147+
# if __cpp_lib_variant != 202306L
8148+
# error "__cpp_lib_variant should have the value 202306L in c++26"
81468149
# endif
81478150

81488151
# ifndef __cpp_lib_void_t

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,11 @@ def add_version_header(tc):
942942
},
943943
{
944944
"name": "__cpp_lib_optional",
945-
"values": {"c++17": 201606, "c++23": 202110},
945+
"values": {
946+
"c++17": 201606,
947+
"c++20": 202106, # P2231R1 Missing constexpr in std::optional and std::variant
948+
"c++23": 202110, # P0798R8 Monadic operations for std::optional + LWG3621 Remove feature-test macro __cpp_lib_monadic_optional
949+
},
946950
"headers": ["optional"],
947951
},
948952
{
@@ -1406,8 +1410,8 @@ def add_version_header(tc):
14061410
"name": "__cpp_lib_variant",
14071411
"values": {
14081412
"c++17": 202102, # std::visit for classes derived from std::variant
1409-
# "c++20": 202106, # Fully constexpr std::variant
1410-
# "c++26": 202306, # Member visit (implemented)
1413+
"c++20": 202106, # P2231R1 Missing constexpr in std::optional and std::variant
1414+
"c++26": 202306, # P2637R3 Member visit
14111415
},
14121416
"headers": ["variant"],
14131417
},

0 commit comments

Comments
 (0)