Skip to content

Commit 02f95b7

Browse files
committed
Revert "[libc++][format] P2637R3: Member visit (std::basic_format_arg) (#76449)"
This reverts commit 7d9b5aa since std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp is failing on Windows when building with Clang-cl.
1 parent ed760d1 commit 02f95b7

15 files changed

+48
-927
lines changed

libcxx/docs/ReleaseNotes/18.rst

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ Implemented Papers
7979
- P1759R6 - Native handles and file streams
8080
- P2868R3 - Remove Deprecated ``std::allocator`` Typedef From C++26
8181
- P2517R1 - Add a conditional ``noexcept`` specification to ``std::apply``
82-
- P2637R3 - Member ``visit``
8382
- P2447R6 - ``span`` over initializer list
8483

8584

libcxx/docs/Status/Cxx2cPapers.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"`P0792R14 <https://wg21.link/P0792R14>`__","LWG","``function_ref``: a type-erased callable reference","Varna June 2023","","",""
1818
"`P2874R2 <https://wg21.link/P2874R2>`__","LWG","Mandating Annex D Require No More","Varna June 2023","","",""
1919
"`P2757R3 <https://wg21.link/P2757R3>`__","LWG","Type-checking format args","Varna June 2023","","","|format|"
20-
"`P2637R3 <https://wg21.link/P2637R3>`__","LWG","Member ``visit``","Varna June 2023","|Complete|","18.0",""
20+
"`P2637R3 <https://wg21.link/P2637R3>`__","LWG","Member ``visit``","Varna June 2023","|Partial|","18.0",""
2121
"`P2641R4 <https://wg21.link/P2641R4>`__","CWG, LWG","Checking if a ``union`` alternative is active","Varna June 2023","","",""
2222
"`P1759R6 <https://wg21.link/P1759R6>`__","LWG","Native handles and file streams","Varna June 2023","|Complete|","18.0",""
2323
"`P2697R1 <https://wg21.link/P2697R1>`__","LWG","Interfacing ``bitset`` with ``string_view``","Varna June 2023","|Complete|","18.0",""

libcxx/docs/Status/FormatIssues.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Number,Name,Standard,Assignee,Status,First released version
1616
"`P2693R1 <https://wg21.link/P2693R1>`__","Formatting ``thread::id`` and ``stacktrace``","C++23","Mark de Wever","|In Progress|"
1717
"`P2510R3 <https://wg21.link/P2510R3>`__","Formatting pointers","C++26","Mark de Wever","|Complete|",17.0
1818
"`P2757R3 <https://wg21.link/P2757R3>`__","Type-checking format args","C++26","","",
19-
"`P2637R3 <https://wg21.link/P2637R3>`__","Member ``visit``","C++26","Hristo Hristov","|Complete|",18.0
19+
"`P2637R3 <https://wg21.link/P2637R3>`__","Member ``visit``","C++26","","",
2020
"`P2905R2 <https://wg21.link/P2905R2>`__","Runtime format strings","C++26 DR","Mark de Wever","|Complete|",18.0
2121
"`P2918R2 <https://wg21.link/P2918R2>`__","Runtime format strings II","C++26","Mark de Wever","|Complete|",18.0
2222
"`P2909R4 <https://wg21.link/P2909R4>`__","Fix formatting of code units as integers (Dude, where’s my ``char``?)","C++26 DR","Mark de Wever","|Complete|",18.0

libcxx/include/__config

-6
Original file line numberDiff line numberDiff line change
@@ -995,12 +995,6 @@ typedef __char32_t char32_t;
995995
# define _LIBCPP_DEPRECATED_IN_CXX23
996996
# endif
997997

998-
# if _LIBCPP_STD_VER >= 26
999-
# define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
1000-
# else
1001-
# define _LIBCPP_DEPRECATED_IN_CXX26
1002-
# endif
1003-
1004998
# if !defined(_LIBCPP_HAS_NO_CHAR8_T)
1005999
# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
10061000
# else

libcxx/include/__format/format_arg.h

+3-106
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr __arg_t __get_packed_type(uint64_t __types, size
9393

9494
} // namespace __format
9595

96-
// This function is not user observable, so it can directly use the non-standard
96+
// This function is not user obervable, so it can directly use the non-standard
9797
// types of the "variant". See __arg_t for more details.
9898
template <class _Visitor, class _Context>
9999
_LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
@@ -144,59 +144,6 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
144144
__libcpp_unreachable();
145145
}
146146

147-
# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
148-
149-
template <class _Rp, class _Visitor, class _Context>
150-
_LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
151-
switch (__arg.__type_) {
152-
case __format::__arg_t::__none:
153-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__monostate_);
154-
case __format::__arg_t::__boolean:
155-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__boolean_);
156-
case __format::__arg_t::__char_type:
157-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__char_type_);
158-
case __format::__arg_t::__int:
159-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__int_);
160-
case __format::__arg_t::__long_long:
161-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__long_long_);
162-
case __format::__arg_t::__i128:
163-
# ifndef _LIBCPP_HAS_NO_INT128
164-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__i128_);
165-
# else
166-
__libcpp_unreachable();
167-
# endif
168-
case __format::__arg_t::__unsigned:
169-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_);
170-
case __format::__arg_t::__unsigned_long_long:
171-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_long_long_);
172-
case __format::__arg_t::__u128:
173-
# ifndef _LIBCPP_HAS_NO_INT128
174-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__u128_);
175-
# else
176-
__libcpp_unreachable();
177-
# endif
178-
case __format::__arg_t::__float:
179-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__float_);
180-
case __format::__arg_t::__double:
181-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__double_);
182-
case __format::__arg_t::__long_double:
183-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__long_double_);
184-
case __format::__arg_t::__const_char_type_ptr:
185-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__const_char_type_ptr_);
186-
case __format::__arg_t::__string_view:
187-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__string_view_);
188-
case __format::__arg_t::__ptr:
189-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__ptr_);
190-
case __format::__arg_t::__handle:
191-
return std::invoke_r<_Rp>(
192-
std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__arg.__value_.__handle_});
193-
}
194-
195-
__libcpp_unreachable();
196-
}
197-
198-
# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
199-
200147
/// Contains the values used in basic_format_arg.
201148
///
202149
/// This is a separate type so it's possible to store the values and types in
@@ -280,52 +227,6 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
280227

281228
_LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
282229

283-
# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
284-
285-
// This function is user facing, so it must wrap the non-standard types of
286-
// the "variant" in a handle to stay conforming. See __arg_t for more details.
287-
template <class _Visitor>
288-
_LIBCPP_HIDE_FROM_ABI decltype(auto) visit(this basic_format_arg __arg, _Visitor&& __vis) {
289-
switch (__arg.__type_) {
290-
# ifndef _LIBCPP_HAS_NO_INT128
291-
case __format::__arg_t::__i128: {
292-
typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_};
293-
return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
294-
}
295-
296-
case __format::__arg_t::__u128: {
297-
typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_};
298-
return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
299-
}
300-
# endif
301-
default:
302-
return std::__visit_format_arg(std::forward<_Visitor>(__vis), __arg);
303-
}
304-
}
305-
306-
// This function is user facing, so it must wrap the non-standard types of
307-
// the "variant" in a handle to stay conforming. See __arg_t for more details.
308-
template <class _Rp, class _Visitor>
309-
_LIBCPP_HIDE_FROM_ABI _Rp visit(this basic_format_arg __arg, _Visitor&& __vis) {
310-
switch (__arg.__type_) {
311-
# ifndef _LIBCPP_HAS_NO_INT128
312-
case __format::__arg_t::__i128: {
313-
typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_};
314-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
315-
}
316-
317-
case __format::__arg_t::__u128: {
318-
typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_};
319-
return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
320-
}
321-
# endif
322-
default:
323-
return std::__visit_format_arg<_Rp>(std::forward<_Visitor>(__vis), __arg);
324-
}
325-
}
326-
327-
# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
328-
329230
private:
330231
using char_type = typename _Context::char_type;
331232

@@ -366,11 +267,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
366267
// This function is user facing, so it must wrap the non-standard types of
367268
// the "variant" in a handle to stay conforming. See __arg_t for more details.
368269
template <class _Visitor, class _Context>
369-
# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
370-
_LIBCPP_DEPRECATED_IN_CXX26
371-
# endif
372-
_LIBCPP_HIDE_FROM_ABI decltype(auto)
373-
visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
270+
_LIBCPP_HIDE_FROM_ABI decltype(auto) visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
374271
switch (__arg.__type_) {
375272
# ifndef _LIBCPP_HAS_NO_INT128
376273
case __format::__arg_t::__i128: {
@@ -382,7 +279,7 @@ _LIBCPP_DEPRECATED_IN_CXX26
382279
typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_};
383280
return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
384281
}
385-
# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
282+
# endif
386283
default:
387284
return std::__visit_format_arg(std::forward<_Visitor>(__vis), __arg);
388285
}

libcxx/include/__format/format_context.h

+14-19
Original file line numberDiff line numberDiff line change
@@ -163,25 +163,20 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
163163
# endif
164164
__ctx_(std::addressof(__ctx)),
165165
__arg_([](void* __c, size_t __id) {
166-
auto __visitor = [&](auto __arg) -> basic_format_arg<basic_format_context> {
167-
if constexpr (same_as<decltype(__arg), monostate>)
168-
return {};
169-
else if constexpr (same_as<decltype(__arg), typename basic_format_arg<_Context>::handle>)
170-
// At the moment it's not possible for formatting to use a re-targeted handle.
171-
// TODO FMT add this when support is needed.
172-
std::__throw_format_error("Re-targeting handle not supported");
173-
else
174-
return basic_format_arg<basic_format_context>{
175-
__format::__determine_arg_t<basic_format_context, decltype(__arg)>(),
176-
__basic_format_arg_value<basic_format_context>(__arg)};
177-
};
178-
# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
179-
return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
180-
# else
181-
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
182-
return std::visit_format_arg(std::move(__visitor), static_cast<_Context*>(__c)->arg(__id));
183-
_LIBCPP_SUPPRESS_DEPRECATED_POP
184-
# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
166+
return std::visit_format_arg(
167+
[&](auto __arg) -> basic_format_arg<basic_format_context> {
168+
if constexpr (same_as<decltype(__arg), monostate>)
169+
return {};
170+
else if constexpr (same_as<decltype(__arg), typename basic_format_arg<_Context>::handle>)
171+
// At the moment it's not possible for formatting to use a re-targeted handle.
172+
// TODO FMT add this when support is needed.
173+
std::__throw_format_error("Re-targeting handle not supported");
174+
else
175+
return basic_format_arg<basic_format_context>{
176+
__format::__determine_arg_t<basic_format_context, decltype(__arg)>(),
177+
__basic_format_arg_value<basic_format_context>(__arg)};
178+
},
179+
static_cast<_Context*>(__c)->arg(__id));
185180
}) {
186181
}
187182

libcxx/include/format

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ namespace std {
170170
template<class Context> class basic_format_arg;
171171
172172
template<class Visitor, class Context>
173-
see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // Deprecated in C++26
173+
see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
174174
175175
// [format.arg.store], class template format-arg-store
176176
template<class Context, class... Args> struct format-arg-store; // exposition only

0 commit comments

Comments
 (0)