[flang-commits] [lld] [llvm] [flang] [openmp] [lldb] [clang] [libcxx] [mlir] [libc] [compiler-rt] [clang-tools-extra] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

Hristo Hristov via flang-commits flang-commits at lists.llvm.org
Fri Jan 19 22:30:43 PST 2024


https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/76449

>From e1ab38976f2d989952a98487e1af114584d2bf9d Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Mon, 25 Dec 2023 11:57:12 +0200
Subject: [PATCH 01/29] [libc++][format] P2637R3: Member visit

Implements parts of: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2637r3.html (https://eel.is/c++draft/format.arg)
---
 libcxx/docs/Status/Cxx2cPapers.csv            |  2 +-
 libcxx/include/__config                       |  6 ++++
 libcxx/include/__format/format_arg.h          | 19 ++++++++++--
 libcxx/include/format                         |  2 +-
 .../format.args/visit.pass.cpp                | 30 +++++++++++++++++++
 .../generate_feature_test_macro_components.py |  1 +
 6 files changed, 56 insertions(+), 4 deletions(-)
 create mode 100644 libcxx/test/std/utilities/format/format.arguments/format.args/visit.pass.cpp

diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..b33543aad8b945 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -17,7 +17,7 @@
 "`P0792R14 <https://wg21.link/P0792R14>`__","LWG","``function_ref``: a type-erased callable reference","Varna June 2023","","",""
 "`P2874R2 <https://wg21.link/P2874R2>`__","LWG","Mandating Annex D Require No More","Varna June 2023","","",""
 "`P2757R3 <https://wg21.link/P2757R3>`__","LWG","Type-checking format args","Varna June 2023","","","|format|"
-"`P2637R3 <https://wg21.link/P2637R3>`__","LWG","Member ``visit``","Varna June 2023","","","|format|"
+"`P2637R3 <https://wg21.link/P2637R3>`__","LWG","Member ``visit``","Varna June 2023","|Complete|","18.0",""
 "`P2641R4 <https://wg21.link/P2641R4>`__","CWG, LWG","Checking if a ``union`` alternative is active","Varna June 2023","","",""
 "`P1759R6 <https://wg21.link/P1759R6>`__","LWG","Native handles and file streams","Varna June 2023","","",""
 "`P2697R1 <https://wg21.link/P2697R1>`__","LWG","Interfacing ``bitset`` with ``string_view``","Varna June 2023","|Complete|","18.0",""
diff --git a/libcxx/include/__config b/libcxx/include/__config
index adff13e714cb64..ee85b73c2e4cfe 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -956,6 +956,12 @@ typedef __char32_t char32_t;
 #    define _LIBCPP_DEPRECATED_IN_CXX23
 #  endif
 
+#  if _LIBCPP_STD_VER >= 26
+#    define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
+#  else
+#    define _LIBCPP_DEPRECATED_IN_CXX26
+#  endif
+
 #  if !defined(_LIBCPP_HAS_NO_CHAR8_T)
 #    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
 #  else
diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index 280c9108241754..62684a3394d010 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -93,7 +93,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr __arg_t __get_packed_type(uint64_t __types, size
 
 } // namespace __format
 
-// This function is not user obervable, so it can directly use the non-standard
+// This function is not user observable, so it can directly use the non-standard
 // types of the "variant". See __arg_t for more details.
 template <class _Visitor, class _Context>
 _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
@@ -227,6 +227,20 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
 
   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
 
+#  if __LIBCPP_VERSION >= 26
+  template <class _Visitor>
+  _LIBCPP_HIDE_FROM_ABI decltype(auto) visit(this basic_format_arg __arg, _Visitor&& __vis) {
+    // TODO: use __visit_format_arg
+    return __arg.__value_.visit(std::forward<_Visitor>(__vis));
+  }
+
+  template <class _Rp, class _Visitor>
+  _LIBCPP_HIDE_FROM_ABI _Rp visit(this basic_format_arg __arg, _Visitor&& __vis) {
+    // TODO:: use __visit_format_arg
+    return __arg.__value_.visit<_Rp>(std::forward<_Visitor>(__vis));
+  }
+#  endif
+
 private:
   using char_type = typename _Context::char_type;
 
@@ -267,7 +281,8 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
 // This function is user facing, so it must wrap the non-standard types of
 // the "variant" in a handle to stay conforming. See __arg_t for more details.
 template <class _Visitor, class _Context>
-_LIBCPP_HIDE_FROM_ABI decltype(auto) visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
+_LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_HIDE_FROM_ABI decltype(auto)
+visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
   switch (__arg.__type_) {
 #  ifndef _LIBCPP_HAS_NO_INT128
   case __format::__arg_t::__i128: {
diff --git a/libcxx/include/format b/libcxx/include/format
index ab9b336d0cdabe..e1566fb4636a7b 100644
--- a/libcxx/include/format
+++ b/libcxx/include/format
@@ -170,7 +170,7 @@ namespace std {
   template<class Context> class basic_format_arg;
 
   template<class Visitor, class Context>
-    see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
+    see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // deprecated in C++26
 
   // [format.arg.store], class template format-arg-store
   template<class Context, class... Args> struct format-arg-store;      // exposition only
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.args/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.args/visit.pass.cpp
new file mode 100644
index 00000000000000..67f822615ce5b9
--- /dev/null
+++ b/libcxx/test/std/utilities/format/format.arguments/format.args/visit.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// <format>
+
+// class basic_format_arg;
+
+// template<class Visitor>
+//   decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);
+// template<class R, class Visitor>
+//   R visit(this basic_format_arg arg, Visitor&& vis);
+
+template <class CharT>
+void test() {}
+
+int main(int, char**) {
+  test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index 2f506f32f565cb..fbd01f8de15962 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -467,6 +467,7 @@ def add_version_header(tc):
                 # "c++20": 202110 Not implemented P2372R3 Fixing locale handling in chrono formatters
                 "c++20": 202106,
                 # "c++23": 202207, Not implemented P2419R2 Clarify handling of encodings in localized formatting of chrono types
+                # "c++26": 202306, # P2637R3 Member Visit
                 # "c++26": 202311, P2918R2 Runtime format strings II (implemented)
             },
             # Note these three papers are adopted at the June 2023 meeting and have sequential numbering

>From 0764fb389d46caa366ee8793e989aa6bc648caa8 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Tue, 26 Dec 2023 11:44:47 +0200
Subject: [PATCH 02/29] Implemented member methods + WIP tests

---
 libcxx/include/__format/format_arg.h          |  59 ++++++++-
 .../visit.pass.cpp                            |   0
 .../visit_format_arg.deprecated.verify.cpp    |  64 ++++++++++
 .../format.arg/visit_format_arg.pass.cpp      | 116 +++++++++---------
 4 files changed, 177 insertions(+), 62 deletions(-)
 rename libcxx/test/std/utilities/format/format.arguments/{format.args => format.arg}/visit.pass.cpp (100%)
 create mode 100644 libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index 62684a3394d010..bc9e13eb9029a5 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -144,6 +144,57 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
   __libcpp_unreachable();
 }
 
+#  if _LIBCPP_STD_VER >= 26
+template <class _Rp, class _Visitor, class _Context>
+_LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
+  switch (__arg.__type_) {
+  case __format::__arg_t::__none:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__monostate_);
+  case __format::__arg_t::__boolean:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__boolean_);
+  case __format::__arg_t::__char_type:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__char_type_);
+  case __format::__arg_t::__int:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__int_);
+  case __format::__arg_t::__long_long:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__long_long_);
+  case __format::__arg_t::__i128:
+#    ifndef _LIBCPP_HAS_NO_INT128
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__i128_);
+#    else
+    __libcpp_unreachable();
+#    endif
+  case __format::__arg_t::__unsigned:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_);
+  case __format::__arg_t::__unsigned_long_long:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_long_long_);
+  case __format::__arg_t::__u128:
+#    ifndef _LIBCPP_HAS_NO_INT128
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__u128_);
+#    else
+    __libcpp_unreachable();
+#    endif
+  case __format::__arg_t::__float:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__float_);
+  case __format::__arg_t::__double:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__double_);
+  case __format::__arg_t::__long_double:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__long_double_);
+  case __format::__arg_t::__const_char_type_ptr:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__const_char_type_ptr_);
+  case __format::__arg_t::__string_view:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__string_view_);
+  case __format::__arg_t::__ptr:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__ptr_);
+  case __format::__arg_t::__handle:
+    return std::invoke_r<_Rp>(
+        std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__arg.__value_.__handle_});
+  }
+
+  __libcpp_unreachable();
+}
+#  endif
+
 /// Contains the values used in basic_format_arg.
 ///
 /// This is a separate type so it's possible to store the values and types in
@@ -227,17 +278,15 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
 
   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
 
-#  if __LIBCPP_VERSION >= 26
+#  if _LIBCPP_STD_VER >= 26
   template <class _Visitor>
   _LIBCPP_HIDE_FROM_ABI decltype(auto) visit(this basic_format_arg __arg, _Visitor&& __vis) {
-    // TODO: use __visit_format_arg
-    return __arg.__value_.visit(std::forward<_Visitor>(__vis));
+    return std::__visit_format_arg(std::forward<_Visitor>(__vis), __arg);
   }
 
   template <class _Rp, class _Visitor>
   _LIBCPP_HIDE_FROM_ABI _Rp visit(this basic_format_arg __arg, _Visitor&& __vis) {
-    // TODO:: use __visit_format_arg
-    return __arg.__value_.visit<_Rp>(std::forward<_Visitor>(__vis));
+    return std::__visit_format_arg<_Rp>(std::forward<_Visitor>(__vis), __arg);
   }
 #  endif
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.args/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
similarity index 100%
rename from libcxx/test/std/utilities/format/format.arguments/format.args/visit.pass.cpp
rename to libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
new file mode 100644
index 00000000000000..2e23b88871b681
--- /dev/null
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// <format>
+
+// template<class Visitor, class Context>
+//   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
+
+#include <algorithm>
+#include <cassert>
+#include <format>
+#include <type_traits>
+
+#include "constexpr_char_traits.h"
+#include "make_string.h"
+#include "min_allocator.h"
+#include "test_macros.h"
+
+template <class Context, class To, class From>
+void test(From value) {
+  auto store = std::make_format_args<Context>(value);
+  std::basic_format_args<Context> format_args{store};
+
+  LIBCPP_ASSERT(format_args.__size() == 1);
+  assert(format_args.get(0));
+
+  // non-member
+  {
+    // expected-warning at +1 {{std::basic_format_context<char *, char>>' is deprecated}}
+    std::visit_format_arg(
+        [v = To(value)](auto a) -> To {
+          if constexpr (std::is_same_v<To, decltype(a)>) {
+            assert(v == a);
+            return a;
+          } else {
+            assert(false);
+            return {};
+          }
+        },
+        format_args.get(0));
+  }
+}
+
+template <class CharT>
+void test() {
+  using Context = std::basic_format_context<CharT*, CharT>;
+  std::basic_string<CharT> empty;
+  std::basic_string<CharT> str = MAKE_STRING(CharT, "abc");
+
+  test<Context, bool>(true);
+}
+
+int main(int, char**) {
+  test<char>();
+
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
index 3ddf2d0ff732a7..3a2f9afe2c5f78 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
@@ -23,6 +23,8 @@
 #include "make_string.h"
 #include "min_allocator.h"
 
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+
 template <class Context, class To, class From>
 void test(From value) {
   auto store = std::make_format_args<Context>(value);
@@ -31,20 +33,41 @@ void test(From value) {
   LIBCPP_ASSERT(format_args.__size() == 1);
   assert(format_args.get(0));
 
-  auto result = std::visit_format_arg(
-      [v = To(value)](auto a) -> To {
-        if constexpr (std::is_same_v<To, decltype(a)>) {
-          assert(v == a);
-          return a;
-        } else {
-          assert(false);
-          return {};
-        }
-      },
-      format_args.get(0));
+#if _LIBCPP_STD_VER >= 26
+  // member
+  {
+    auto result = format_args.get(0).visit([v = To(value)](auto a) -> To {
+      if constexpr (std::is_same_v<To, decltype(a)>) {
+        assert(v == a);
+        return a;
+      } else {
+        assert(false);
+        return {};
+      }
+    });
+
+    using ct = std::common_type_t<From, To>;
+    assert(static_cast<ct>(result) == static_cast<ct>(value));
+  }
+#endif
 
-  using ct = std::common_type_t<From, To>;
-  assert(static_cast<ct>(result) == static_cast<ct>(value));
+  // non-member
+  {
+    auto result = std::visit_format_arg(
+        [v = To(value)](auto a) -> To {
+          if constexpr (std::is_same_v<To, decltype(a)>) {
+            assert(v == a);
+            return a;
+          } else {
+            assert(false);
+            return {};
+          }
+        },
+        format_args.get(0));
+
+    using ct = std::common_type_t<From, To>;
+    assert(static_cast<ct>(result) == static_cast<ct>(value));
+  }
 }
 
 // Some types, as an extension, are stored in the variant. The Standard
@@ -75,8 +98,8 @@ void test_string_view(From value) {
   assert(format_args.get(0));
 
   using CharT = typename Context::char_type;
-  using To = std::basic_string_view<CharT>;
-  using V = std::basic_string<CharT>;
+  using To    = std::basic_string_view<CharT>;
+  using V     = std::basic_string<CharT>;
   auto result = std::visit_format_arg(
       [v = V(value.begin(), value.end())](auto a) -> To {
         if constexpr (std::is_same_v<To, decltype(a)>) {
@@ -170,8 +193,7 @@ void test() {
   test<Context, int, int>(std::numeric_limits<short>::max());
   test<Context, int, int>(std::numeric_limits<int>::max());
 
-  using LongToType =
-      std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
+  using LongToType = std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
 
   test<Context, LongToType, long>(std::numeric_limits<long>::min());
   test<Context, LongToType, long>(std::numeric_limits<int>::min());
@@ -202,14 +224,11 @@ void test() {
   // Test unsigned integer types.
 
   test<Context, unsigned, unsigned char>(0);
-  test<Context, unsigned, unsigned char>(
-      std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned char>(std::numeric_limits<unsigned char>::max());
 
   test<Context, unsigned, unsigned short>(0);
-  test<Context, unsigned, unsigned short>(
-      std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned, unsigned short>(
-      std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned short>::max());
 
   test<Context, unsigned, unsigned>(0);
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned char>::max());
@@ -217,30 +236,20 @@ void test() {
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned>::max());
 
   using UnsignedLongToType =
-      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned,
-                         unsigned long long>;
+      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned, unsigned long long>;
 
   test<Context, UnsignedLongToType, unsigned long>(0);
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned char>::max());
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned short>::max());
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned>::max());
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned long>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned char>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned short>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned long>::max());
 
   test<Context, unsigned long long, unsigned long long>(0);
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned short>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned long>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned long long>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long long>::max());
 
 #ifndef TEST_HAS_NO_INT128
   test_handle<Context, __uint128_t>(0);
@@ -262,16 +271,12 @@ void test() {
   test<Context, double, double>(std::numeric_limits<double>::min());
   test<Context, double, double>(std::numeric_limits<double>::max());
 
-  test<Context, long double, long double>(
-      -std::numeric_limits<long double>::max());
-  test<Context, long double, long double>(
-      -std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(-std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(-std::numeric_limits<long double>::min());
   test<Context, long double, long double>(-0.0);
   test<Context, long double, long double>(0.0);
-  test<Context, long double, long double>(
-      std::numeric_limits<long double>::min());
-  test<Context, long double, long double>(
-      std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(std::numeric_limits<long double>::max());
 
   // Test const CharT pointer types.
 
@@ -307,8 +312,7 @@ void test() {
   }
 
   {
-    using From = std::basic_string<CharT, constexpr_char_traits<CharT>,
-                                   std::allocator<CharT>>;
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>, std::allocator<CharT>>;
 
     test_string_view<Context>(From());
     test_string_view<Context>(From(empty.c_str()));
@@ -316,8 +320,7 @@ void test() {
   }
 
   {
-    using From =
-        std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
+    using From = std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
 
     test_string_view<Context>(From());
     test_string_view<Context>(From(empty.c_str()));
@@ -325,8 +328,7 @@ void test() {
   }
 
   {
-    using From = std::basic_string<CharT, constexpr_char_traits<CharT>,
-                                   min_allocator<CharT>>;
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>, min_allocator<CharT>>;
 
     test_string_view<Context>(From());
     test_string_view<Context>(From(empty.c_str()));

>From 7a70aa6a42da5d1f60a3c05e2b7e22fc08298f11 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Tue, 26 Dec 2023 14:24:32 +0200
Subject: [PATCH 03/29] Added `visit` with return type test WIP

---
 libcxx/include/__format/format_arg.h          | 63 +++++++++++--
 .../format.arg/visit.pass.cpp                 | 30 -------
 .../format.arg/visit.return_type.pass.cpp     | 89 +++++++++++++++++++
 .../format.arg/visit_format_arg.pass.cpp      |  4 +-
 4 files changed, 148 insertions(+), 38 deletions(-)
 delete mode 100644 libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
 create mode 100644 libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index bc9e13eb9029a5..eb16326e2a72e8 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -145,6 +145,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
 }
 
 #  if _LIBCPP_STD_VER >= 26
+#    if 1
 template <class _Rp, class _Visitor, class _Context>
 _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
   switch (__arg.__type_) {
@@ -159,21 +160,21 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
   case __format::__arg_t::__long_long:
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__long_long_);
   case __format::__arg_t::__i128:
-#    ifndef _LIBCPP_HAS_NO_INT128
+#      ifndef _LIBCPP_HAS_NO_INT128
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__i128_);
-#    else
+#      else
     __libcpp_unreachable();
-#    endif
+#      endif
   case __format::__arg_t::__unsigned:
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_);
   case __format::__arg_t::__unsigned_long_long:
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_long_long_);
   case __format::__arg_t::__u128:
-#    ifndef _LIBCPP_HAS_NO_INT128
+#      ifndef _LIBCPP_HAS_NO_INT128
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__u128_);
-#    else
+#      else
     __libcpp_unreachable();
-#    endif
+#      endif
   case __format::__arg_t::__float:
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__float_);
   case __format::__arg_t::__double:
@@ -193,6 +194,56 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
 
   __libcpp_unreachable();
 }
+#    else
+template <class _Rp, class _Visitor, class _Context>
+_LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
+  switch (__arg.__type_) {
+  case __format::__arg_t::__none:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__monostate_));
+  case __format::__arg_t::__boolean:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__boolean_));
+  case __format::__arg_t::__char_type:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__char_type_));
+  case __format::__arg_t::__int:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__int_));
+  case __format::__arg_t::__long_long:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__long_long_));
+  case __format::__arg_t::__i128:
+#      ifndef _LIBCPP_HAS_NO_INT128
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__i128_));
+#      else
+    __libcpp_unreachable();
+#      endif
+  case __format::__arg_t::__unsigned:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__unsigned_));
+  case __format::__arg_t::__unsigned_long_long:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__unsigned_long_long_));
+  case __format::__arg_t::__u128:
+#      ifndef _LIBCPP_HAS_NO_INT128
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__u128_));
+#      else
+    __libcpp_unreachable();
+#      endif
+  case __format::__arg_t::__float:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__float_));
+  case __format::__arg_t::__double:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__double_));
+  case __format::__arg_t::__long_double:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__long_double_));
+  case __format::__arg_t::__const_char_type_ptr:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__const_char_type_ptr_));
+  case __format::__arg_t::__string_view:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__string_view_));
+  case __format::__arg_t::__ptr:
+    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__ptr_));
+  case __format::__arg_t::__handle:
+    return std::invoke_r<_Rp>(
+        std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__arg.__value_.__handle_});
+  }
+
+  __libcpp_unreachable();
+}
+#    endif //
 #  endif
 
 /// Contains the values used in basic_format_arg.
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
deleted file mode 100644
index 67f822615ce5b9..00000000000000
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===----------------------------------------------------------------------===//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
-// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
-
-// <format>
-
-// class basic_format_arg;
-
-// template<class Visitor>
-//   decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);
-// template<class R, class Visitor>
-//   R visit(this basic_format_arg arg, Visitor&& vis);
-
-template <class CharT>
-void test() {}
-
-int main(int, char**) {
-  test<char>();
-#ifndef TEST_HAS_NO_WIDE_CHARACTERS
-  test<wchar_t>();
-#endif
-
-  return 0;
-}
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
new file mode 100644
index 00000000000000..2a34b1974aa84d
--- /dev/null
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// <format>
+
+// class basic_format_arg;
+
+// template<class Visitor>
+//   decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);
+// template<class R, class Visitor>
+//   R visit(this basic_format_arg arg, Visitor&& vis);
+
+#include <algorithm>
+#include <cassert>
+#include <format>
+#include <type_traits>
+
+#include "constexpr_char_traits.h"
+#include "make_string.h"
+#include "min_allocator.h"
+#include "test_macros.h"
+
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+
+template <class Context, class To, class ExpectedResult, class From>
+void test(From value, ExpectedResult expectedValue) {
+  auto store = std::make_format_args<Context>(value);
+  std::basic_format_args<Context> format_args{store};
+
+  LIBCPP_ASSERT(format_args.__size() == 1);
+  assert(format_args.get(0));
+
+  // member
+  {
+    std::same_as<ExpectedResult> decltype(auto) result =
+        format_args.get(0).template visit<ExpectedResult>([v = To(value)](auto a) -> ExpectedResult {
+          if constexpr (std::is_same_v<To, decltype(a)>) {
+            assert(v == a);
+
+            if constexpr (std::is_same_v<ExpectedResult, bool>) {
+              return true;
+            } else if constexpr (std::is_same_v<ExpectedResult, long>) {
+              return 192812079084L;
+            } else {
+              return "visited";
+            }
+          } else {
+            assert(false);
+            return {};
+          }
+        });
+
+    assert(result == expectedValue);
+  }
+}
+
+template <class CharT>
+void test() {
+  using Context = std::basic_format_context<CharT*, CharT>;
+  std::basic_string<CharT> empty;
+  std::basic_string<CharT> str = MAKE_STRING(CharT, "abc");
+
+  // Test boolean types.
+
+  test<Context, bool, std::string>(true, "visited");
+  test<Context, bool, std::string>(false, "visited");
+
+  test<Context, bool, bool>(true, true);
+  test<Context, bool, bool>(false, true);
+
+  test<Context, bool, long>(true, 192812079084L);
+  test<Context, bool, long>(false, 192812079084L);
+}
+
+int main(int, char**) {
+  test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
index 3a2f9afe2c5f78..c8731a25267d22 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
@@ -14,14 +14,14 @@
 //   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
 
 #include <algorithm>
-#include <format>
 #include <cassert>
+#include <format>
 #include <type_traits>
 
 #include "constexpr_char_traits.h"
-#include "test_macros.h"
 #include "make_string.h"
 #include "min_allocator.h"
+#include "test_macros.h"
 
 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
 

>From fbdd8ac0c0d7d96cc35285e0c94a7f18594ccff7 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Tue, 26 Dec 2023 14:32:34 +0200
Subject: [PATCH 04/29] WIP: visit.return_type.pass

---
 libcxx/include/__format/format_arg.h          | 51 -------------------
 ...sit_format_arg.pass.cpp => visit.pass.cpp} |  7 ++-
 .../format.arg/visit.return_type.pass.cpp     |  9 +++-
 3 files changed, 13 insertions(+), 54 deletions(-)
 rename libcxx/test/std/utilities/format/format.arguments/format.arg/{visit_format_arg.pass.cpp => visit.pass.cpp} (98%)

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index eb16326e2a72e8..1724c7c1dd3c8f 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -145,7 +145,6 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
 }
 
 #  if _LIBCPP_STD_VER >= 26
-#    if 1
 template <class _Rp, class _Visitor, class _Context>
 _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
   switch (__arg.__type_) {
@@ -194,56 +193,6 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
 
   __libcpp_unreachable();
 }
-#    else
-template <class _Rp, class _Visitor, class _Context>
-_LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
-  switch (__arg.__type_) {
-  case __format::__arg_t::__none:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__monostate_));
-  case __format::__arg_t::__boolean:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__boolean_));
-  case __format::__arg_t::__char_type:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__char_type_));
-  case __format::__arg_t::__int:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__int_));
-  case __format::__arg_t::__long_long:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__long_long_));
-  case __format::__arg_t::__i128:
-#      ifndef _LIBCPP_HAS_NO_INT128
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__i128_));
-#      else
-    __libcpp_unreachable();
-#      endif
-  case __format::__arg_t::__unsigned:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__unsigned_));
-  case __format::__arg_t::__unsigned_long_long:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__unsigned_long_long_));
-  case __format::__arg_t::__u128:
-#      ifndef _LIBCPP_HAS_NO_INT128
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__u128_));
-#      else
-    __libcpp_unreachable();
-#      endif
-  case __format::__arg_t::__float:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__float_));
-  case __format::__arg_t::__double:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__double_));
-  case __format::__arg_t::__long_double:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__long_double_));
-  case __format::__arg_t::__const_char_type_ptr:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__const_char_type_ptr_));
-  case __format::__arg_t::__string_view:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__string_view_));
-  case __format::__arg_t::__ptr:
-    return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), std::move(__arg.__value_.__ptr_));
-  case __format::__arg_t::__handle:
-    return std::invoke_r<_Rp>(
-        std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__arg.__value_.__handle_});
-  }
-
-  __libcpp_unreachable();
-}
-#    endif //
 #  endif
 
 /// Contains the values used in basic_format_arg.
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
similarity index 98%
rename from libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
rename to libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
index c8731a25267d22..efc52b6cffbda5 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
@@ -10,8 +10,13 @@
 
 // <format>
 
+// class basic_format_arg;
+
+// template<class Visitor>
+//   decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);  // since C++26
+
 // template<class Visitor, class Context>
-//   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
+//   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // deprecated in C++26
 
 #include <algorithm>
 #include <cassert>
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
index 2a34b1974aa84d..400f6333f7461d 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
@@ -12,8 +12,6 @@
 
 // class basic_format_arg;
 
-// template<class Visitor>
-//   decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);
 // template<class R, class Visitor>
 //   R visit(this basic_format_arg arg, Visitor&& vis);
 
@@ -77,6 +75,13 @@ void test() {
 
   test<Context, bool, long>(true, 192812079084L);
   test<Context, bool, long>(false, 192812079084L);
+
+  // Test CharT types.
+
+  test<Context, CharT, std::string, CharT>('a', "visited");
+  test<Context, CharT, std::string, CharT>('z', "visited");
+  test<Context, CharT, std::string, CharT>('0', "visited");
+  test<Context, CharT, std::string, CharT>('9', "visited");
 }
 
 int main(int, char**) {

>From 91348f1a93bff67867e483cffbc7bac5ff2560d9 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Wed, 27 Dec 2023 13:52:44 +0200
Subject: [PATCH 05/29] WIP: visit.return_type.pass

---
 .../format.arg/visit.pass.cpp                 |   1 +
 .../format.arg/visit.return_type.pass.cpp     | 272 ++++++++++++++++--
 2 files changed, 253 insertions(+), 20 deletions(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
index efc52b6cffbda5..c3b1609c159c8d 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
@@ -28,6 +28,7 @@
 #include "min_allocator.h"
 #include "test_macros.h"
 
+// Deprecated `std::visit_format_arg` should be tested in C++26 or newer.
 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
 
 template <class Context, class To, class From>
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
index 400f6333f7461d..86a09fee20eebd 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
@@ -25,10 +25,23 @@
 #include "min_allocator.h"
 #include "test_macros.h"
 
-TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+// The expected result type shouldn't matter,therefore use a hardcoded value for simplicity.
+using ExpectedResultType = bool;
+constexpr ExpectedResultType visited{true};
 
-template <class Context, class To, class ExpectedResult, class From>
-void test(From value, ExpectedResult expectedValue) {
+template <class ExpectedR>
+ExpectedR make_expected_result() {
+  if constexpr (std::is_same_v<ExpectedR, bool>) {
+    return true;
+  } else if constexpr (std::is_same_v<ExpectedR, long>) {
+    return 192812079084L;
+  } else {
+    return "visited";
+  }
+}
+
+template <class Context, class To, class ExpectedR, class From>
+void test(From value, const ExpectedR& expectedValue) {
   auto store = std::make_format_args<Context>(value);
   std::basic_format_args<Context> format_args{store};
 
@@ -37,18 +50,11 @@ void test(From value, ExpectedResult expectedValue) {
 
   // member
   {
-    std::same_as<ExpectedResult> decltype(auto) result =
-        format_args.get(0).template visit<ExpectedResult>([v = To(value)](auto a) -> ExpectedResult {
+    std::same_as<ExpectedR> decltype(auto) result =
+        format_args.get(0).template visit<ExpectedR>([v = To(value)](auto a) -> ExpectedR {
           if constexpr (std::is_same_v<To, decltype(a)>) {
             assert(v == a);
-
-            if constexpr (std::is_same_v<ExpectedResult, bool>) {
-              return true;
-            } else if constexpr (std::is_same_v<ExpectedResult, long>) {
-              return 192812079084L;
-            } else {
-              return "visited";
-            }
+            return make_expected_result<ExpectedR>();
           } else {
             assert(false);
             return {};
@@ -59,6 +65,57 @@ void test(From value, ExpectedResult expectedValue) {
   }
 }
 
+// Some types, as an extension, are stored in the variant. The Standard
+// requires them to be observed as a handle.
+template <class Context, class T, class ExpectedR>
+void test_handle(T value, ExpectedR expectedValue) {
+  auto store = std::make_format_args<Context>(value);
+  std::basic_format_args<Context> format_args{store};
+
+  LIBCPP_ASSERT(format_args.__size() == 1);
+  assert(format_args.get(0));
+
+  std::same_as<ExpectedR> decltype(auto) result = format_args.get(0).template visit<ExpectedR>([](auto a) -> ExpectedR {
+    // TODO: This check fails
+    (void) a;
+    // assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>));
+
+    return make_expected_result<ExpectedR>();
+  });
+
+  assert(result == expectedValue);
+}
+
+// Test specific for string and string_view.
+//
+// Since both result in a string_view there's no need to pass this as a
+// template argument.
+template <class Context, class ExpectedR, class From>
+void test_string_view(From value, ExpectedR expectedValue) {
+  auto store = std::make_format_args<Context>(value);
+  std::basic_format_args<Context> format_args{store};
+
+  LIBCPP_ASSERT(format_args.__size() == 1);
+  assert(format_args.get(0));
+
+  using CharT = typename Context::char_type;
+  using To    = std::basic_string_view<CharT>;
+  using V     = std::basic_string<CharT>;
+
+  std::same_as<ExpectedR> decltype(auto) result =
+      format_args.get(0).template visit<ExpectedR>([v = V(value.begin(), value.end())](auto a) -> ExpectedR {
+        if constexpr (std::is_same_v<To, decltype(a)>) {
+          assert(v == a);
+          return make_expected_result<ExpectedR>();
+        } else {
+          assert(false);
+          return {};
+        }
+      });
+
+  assert(result == expectedValue);
+}
+
 template <class CharT>
 void test() {
   using Context = std::basic_format_context<CharT*, CharT>;
@@ -67,21 +124,196 @@ void test() {
 
   // Test boolean types.
 
+  test<Context, bool, ExpectedResultType>(true, visited);
+  test<Context, bool, ExpectedResultType>(false, visited);
+
   test<Context, bool, std::string>(true, "visited");
   test<Context, bool, std::string>(false, "visited");
 
-  test<Context, bool, bool>(true, true);
-  test<Context, bool, bool>(false, true);
-
   test<Context, bool, long>(true, 192812079084L);
   test<Context, bool, long>(false, 192812079084L);
 
   // Test CharT types.
 
-  test<Context, CharT, std::string, CharT>('a', "visited");
-  test<Context, CharT, std::string, CharT>('z', "visited");
-  test<Context, CharT, std::string, CharT>('0', "visited");
-  test<Context, CharT, std::string, CharT>('9', "visited");
+  test<Context, CharT, ExpectedResultType, CharT>('a', visited);
+  test<Context, CharT, ExpectedResultType, CharT>('z', visited);
+  test<Context, CharT, ExpectedResultType, CharT>('0', visited);
+  test<Context, CharT, ExpectedResultType, CharT>('9', visited);
+
+  // Test char types.
+
+  if (std::is_same_v<CharT, char>) {
+    // char to char -> char
+    test<Context, CharT, ExpectedResultType, char>('a', visited);
+    test<Context, CharT, ExpectedResultType, char>('z', visited);
+    test<Context, CharT, ExpectedResultType, char>('0', visited);
+    test<Context, CharT, ExpectedResultType, char>('9', visited);
+  } else {
+    if (std::is_same_v<CharT, wchar_t>) {
+      // char to wchar_t -> wchar_t
+      test<Context, wchar_t, ExpectedResultType, char>('a', visited);
+      test<Context, wchar_t, ExpectedResultType, char>('z', visited);
+      test<Context, wchar_t, ExpectedResultType, char>('0', visited);
+      test<Context, wchar_t, ExpectedResultType, char>('9', visited);
+    } else if (std::is_signed_v<char>) {
+      // char to CharT -> int
+      // This happens when CharT is a char8_t, char16_t, or char32_t and char
+      // is a signed type.
+      // Note if sizeof(CharT) > sizeof(int) this test fails. If there are
+      // platforms where that occurs extra tests need to be added for char32_t
+      // testing it against a long long.
+      test<Context, int, ExpectedResultType, char>('a', visited);
+      test<Context, int, ExpectedResultType, char>('z', visited);
+      test<Context, int, ExpectedResultType, char>('0', visited);
+      test<Context, int, ExpectedResultType, char>('9', visited);
+    } else {
+      // char to CharT -> unsigned
+      // This happens when CharT is a char8_t, char16_t, or char32_t and char
+      // is an unsigned type.
+      // Note if sizeof(CharT) > sizeof(unsigned) this test fails. If there are
+      // platforms where that occurs extra tests need to be added for char32_t
+      // testing it against an unsigned long long.
+      test<Context, unsigned, ExpectedResultType, char>('a', visited);
+      test<Context, unsigned, ExpectedResultType, char>('z', visited);
+      test<Context, unsigned, ExpectedResultType, char>('0', visited);
+      test<Context, unsigned, ExpectedResultType, char>('9', visited);
+    }
+  }
+
+  // Test signed integer types.
+
+  test<Context, int, ExpectedResultType, signed char>(std::numeric_limits<signed char>::min(), visited);
+  test<Context, int, ExpectedResultType, signed char>(0, visited);
+  test<Context, int, ExpectedResultType, signed char>(std::numeric_limits<signed char>::max(), visited);
+
+  test<Context, int, ExpectedResultType, short>(std::numeric_limits<short>::min(), visited);
+  test<Context, int, ExpectedResultType, short>(std::numeric_limits<signed char>::min(), visited);
+  test<Context, int, ExpectedResultType, short>(0, visited);
+  test<Context, int, ExpectedResultType, short>(std::numeric_limits<signed char>::max(), visited);
+  test<Context, int, ExpectedResultType, short>(std::numeric_limits<short>::max(), visited);
+
+  test<Context, int, ExpectedResultType, int>(std::numeric_limits<int>::min(), visited);
+  test<Context, int, ExpectedResultType, int>(std::numeric_limits<short>::min(), visited);
+  test<Context, int, ExpectedResultType, int>(std::numeric_limits<signed char>::min(), visited);
+  test<Context, int, ExpectedResultType, int>(0, visited);
+  test<Context, int, ExpectedResultType, int>(std::numeric_limits<signed char>::max(), visited);
+  test<Context, int, ExpectedResultType, int>(std::numeric_limits<short>::max(), visited);
+  test<Context, int, ExpectedResultType, int>(std::numeric_limits<int>::max(), visited);
+
+  using LongToType = std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
+
+  test<Context, LongToType, ExpectedResultType, long>(std::numeric_limits<long>::min(), visited);
+  test<Context, LongToType, ExpectedResultType, long>(std::numeric_limits<int>::min(), visited);
+  test<Context, LongToType, ExpectedResultType, long>(std::numeric_limits<short>::min(), visited);
+  test<Context, LongToType, ExpectedResultType, long>(std::numeric_limits<signed char>::min(), visited);
+  test<Context, LongToType, ExpectedResultType, long>(0, visited);
+  test<Context, LongToType, ExpectedResultType, long>(std::numeric_limits<signed char>::max(), visited);
+  test<Context, LongToType, ExpectedResultType, long>(std::numeric_limits<short>::max(), visited);
+  test<Context, LongToType, ExpectedResultType, long>(std::numeric_limits<int>::max(), visited);
+  test<Context, LongToType, ExpectedResultType, long>(std::numeric_limits<long>::max(), visited);
+
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<long long>::min(), visited);
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<long>::min(), visited);
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<int>::min(), visited);
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<short>::min(), visited);
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<signed char>::min(), visited);
+  test<Context, long long, ExpectedResultType, long long>(0, visited);
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<signed char>::max(), visited);
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<short>::max(), visited);
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<int>::max(), visited);
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<long>::max(), visited);
+  test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<long long>::max(), visited);
+
+#ifndef TEST_HAS_NO_INT128
+  test_handle<Context, __uint128_t, ExpectedResultType>(0, visited);
+#endif // TEST_HAS_NO_INT128
+
+  // Test floating point types.
+
+  test<Context, float, ExpectedResultType, float>(-std::numeric_limits<float>::max(), visited);
+  test<Context, float, ExpectedResultType, float>(-std::numeric_limits<float>::min(), visited);
+  test<Context, float, ExpectedResultType, float>(-0.0, visited);
+  test<Context, float, ExpectedResultType, float>(0.0, visited);
+  test<Context, float, ExpectedResultType, float>(std::numeric_limits<float>::min(), visited);
+  test<Context, float, ExpectedResultType, float>(std::numeric_limits<float>::max(), visited);
+
+  test<Context, double, ExpectedResultType, double>(-std::numeric_limits<double>::max(), visited);
+  test<Context, double, ExpectedResultType, double>(-std::numeric_limits<double>::min(), visited);
+  test<Context, double, ExpectedResultType, double>(-0.0, visited);
+  test<Context, double, ExpectedResultType, double>(0.0, visited);
+  test<Context, double, ExpectedResultType, double>(std::numeric_limits<double>::min(), visited);
+  test<Context, double, ExpectedResultType, double>(std::numeric_limits<double>::max(), visited);
+
+  test<Context, long double, ExpectedResultType, long double>(-std::numeric_limits<long double>::max(), visited);
+  test<Context, long double, ExpectedResultType, long double>(-std::numeric_limits<long double>::min(), visited);
+  test<Context, long double, ExpectedResultType, long double>(-0.0, visited);
+  test<Context, long double, ExpectedResultType, long double>(0.0, visited);
+  test<Context, long double, ExpectedResultType, long double>(std::numeric_limits<long double>::min(), visited);
+  test<Context, long double, ExpectedResultType, long double>(std::numeric_limits<long double>::max(), visited);
+
+  // Test const CharT pointer types.
+
+  test<Context, const CharT*, ExpectedResultType, const CharT*>(empty.c_str(), visited);
+  test<Context, const CharT*, ExpectedResultType, const CharT*>(str.c_str(), visited);
+
+  // Test string_view types.
+
+  {
+    using From = std::basic_string_view<CharT>;
+
+    test_string_view<Context, ExpectedResultType>(From(), visited);
+    test_string_view<Context, ExpectedResultType>(From(empty.c_str()), visited);
+    test_string_view<Context, ExpectedResultType>(From(str.c_str()), visited);
+  }
+  {
+    using From = std::basic_string_view<CharT, constexpr_char_traits<CharT>>;
+
+    test_string_view<Context, ExpectedResultType>(From(), visited);
+    test_string_view<Context, ExpectedResultType>(From(empty.c_str()), visited);
+    test_string_view<Context, ExpectedResultType>(From(str.c_str()), visited);
+  }
+
+  // Test string types.
+
+  {
+    using From = std::basic_string<CharT>;
+
+    test_string_view<Context, ExpectedResultType>(From(), visited);
+    test_string_view<Context, ExpectedResultType>(From(empty.c_str()), visited);
+    test_string_view<Context, ExpectedResultType>(From(str.c_str()), visited);
+  }
+
+  {
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>, std::allocator<CharT>>;
+
+    test_string_view<Context, ExpectedResultType>(From(), visited);
+    test_string_view<Context, ExpectedResultType>(From(empty.c_str()), visited);
+    test_string_view<Context, ExpectedResultType>(From(str.c_str()), visited);
+  }
+
+  {
+    using From = std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
+
+    test_string_view<Context, ExpectedResultType>(From(), visited);
+    test_string_view<Context, ExpectedResultType>(From(empty.c_str()), visited);
+    test_string_view<Context, ExpectedResultType>(From(str.c_str()), visited);
+  }
+
+  {
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>, min_allocator<CharT>>;
+
+    test_string_view<Context, ExpectedResultType>(From(), visited);
+    test_string_view<Context, ExpectedResultType>(From(empty.c_str()), visited);
+    test_string_view<Context, ExpectedResultType>(From(str.c_str()), visited);
+  }
+
+  // Test pointer types.
+
+  test<Context, const void*, ExpectedResultType>(nullptr, visited);
+  int i = 0;
+  test<Context, const void*, ExpectedResultType>(static_cast<void*>(&i), visited);
+  const int ci = 0;
+  test<Context, const void*, ExpectedResultType>(static_cast<const void*>(&ci), visited);
 }
 
 int main(int, char**) {

>From ebab5b6c85632fbca725995950ac0e10f59b9d8b Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Wed, 27 Dec 2023 17:55:44 +0200
Subject: [PATCH 06/29] Fixed formatting

---
 .../format.arguments/format.arg/visit.return_type.pass.cpp      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
index 86a09fee20eebd..470df35ef97196 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
@@ -77,7 +77,7 @@ void test_handle(T value, ExpectedR expectedValue) {
 
   std::same_as<ExpectedR> decltype(auto) result = format_args.get(0).template visit<ExpectedR>([](auto a) -> ExpectedR {
     // TODO: This check fails
-    (void) a;
+    (void)a;
     // assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>));
 
     return make_expected_result<ExpectedR>();

>From 1b8e407a2e4ce95ef14251ebb36b812c93cac744 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Wed, 27 Dec 2023 18:02:38 +0200
Subject: [PATCH 07/29] Fixed formatting

---
 libcxx/include/__format/format_arg.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index 1724c7c1dd3c8f..bc9e13eb9029a5 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -159,21 +159,21 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
   case __format::__arg_t::__long_long:
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__long_long_);
   case __format::__arg_t::__i128:
-#      ifndef _LIBCPP_HAS_NO_INT128
+#    ifndef _LIBCPP_HAS_NO_INT128
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__i128_);
-#      else
+#    else
     __libcpp_unreachable();
-#      endif
+#    endif
   case __format::__arg_t::__unsigned:
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_);
   case __format::__arg_t::__unsigned_long_long:
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_long_long_);
   case __format::__arg_t::__u128:
-#      ifndef _LIBCPP_HAS_NO_INT128
+#    ifndef _LIBCPP_HAS_NO_INT128
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__u128_);
-#      else
+#    else
     __libcpp_unreachable();
-#      endif
+#    endif
   case __format::__arg_t::__float:
     return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__float_);
   case __format::__arg_t::__double:

>From a6e6aaaa00cd3a0d91624a34f7804edd4c89234e Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Fri, 29 Dec 2023 17:41:08 +0200
Subject: [PATCH 08/29] Restored: visit_format_arg.pass.cpp + docs upate

---
 libcxx/docs/ReleaseNotes/18.rst               |   1 +
 libcxx/docs/Status/FormatIssues.csv           |   2 +-
 .../format.arg/visit_format_arg.pass.cpp      | 352 ++++++++++++++++++
 .../generate_feature_test_macro_components.py |   2 +-
 4 files changed, 355 insertions(+), 2 deletions(-)
 create mode 100644 libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp

diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index 79608c631f1e62..a9643e382285af 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -57,6 +57,7 @@ Implemented Papers
 - P2871R3 - Remove Deprecated Unicode Conversion Facets from C++26
 - P2870R3 - Remove basic_string::reserve()
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my ``char``?)
+- P2637R3 - Member `visit`
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/FormatIssues.csv b/libcxx/docs/Status/FormatIssues.csv
index 513988d08036ca..6e58e752191ea5 100644
--- a/libcxx/docs/Status/FormatIssues.csv
+++ b/libcxx/docs/Status/FormatIssues.csv
@@ -16,7 +16,7 @@ Number,Name,Standard,Assignee,Status,First released version
 "`P2693R1 <https://wg21.link/P2693R1>`__","Formatting ``thread::id`` and ``stacktrace``","C++23","Mark de Wever","|In Progress|"
 "`P2510R3 <https://wg21.link/P2510R3>`__","Formatting pointers","C++26","Mark de Wever","|Complete|",17.0
 "`P2757R3 <https://wg21.link/P2757R3>`__","Type-checking format args","C++26","","",
-"`P2637R3 <https://wg21.link/P2637R3>`__","Member ``visit``","C++26","","",
+"`P2637R3 <https://wg21.link/P2637R3>`__","Member ``visit``","C++26","Hristo Hristov","|Complete|",18.0
 "`P2905R2 <https://wg21.link/P2905R2>`__","Runtime format strings","C++26 DR","Mark de Wever","|Complete|",18.0
 "`P2918R2 <https://wg21.link/P2918R2>`__","Runtime format strings II","C++26","Mark de Wever","|Complete|",18.0
 "`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
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
new file mode 100644
index 00000000000000..3ddf2d0ff732a7
--- /dev/null
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
@@ -0,0 +1,352 @@
+//===----------------------------------------------------------------------===//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// <format>
+
+// template<class Visitor, class Context>
+//   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
+
+#include <algorithm>
+#include <format>
+#include <cassert>
+#include <type_traits>
+
+#include "constexpr_char_traits.h"
+#include "test_macros.h"
+#include "make_string.h"
+#include "min_allocator.h"
+
+template <class Context, class To, class From>
+void test(From value) {
+  auto store = std::make_format_args<Context>(value);
+  std::basic_format_args<Context> format_args{store};
+
+  LIBCPP_ASSERT(format_args.__size() == 1);
+  assert(format_args.get(0));
+
+  auto result = std::visit_format_arg(
+      [v = To(value)](auto a) -> To {
+        if constexpr (std::is_same_v<To, decltype(a)>) {
+          assert(v == a);
+          return a;
+        } else {
+          assert(false);
+          return {};
+        }
+      },
+      format_args.get(0));
+
+  using ct = std::common_type_t<From, To>;
+  assert(static_cast<ct>(result) == static_cast<ct>(value));
+}
+
+// Some types, as an extension, are stored in the variant. The Standard
+// requires them to be observed as a handle.
+template <class Context, class T>
+void test_handle(T value) {
+  auto store = std::make_format_args<Context>(value);
+  std::basic_format_args<Context> format_args{store};
+
+  LIBCPP_ASSERT(format_args.__size() == 1);
+  assert(format_args.get(0));
+
+  std::visit_format_arg(
+      [](auto a) { assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>)); },
+      format_args.get(0));
+}
+
+// Test specific for string and string_view.
+//
+// Since both result in a string_view there's no need to pass this as a
+// template argument.
+template <class Context, class From>
+void test_string_view(From value) {
+  auto store = std::make_format_args<Context>(value);
+  std::basic_format_args<Context> format_args{store};
+
+  LIBCPP_ASSERT(format_args.__size() == 1);
+  assert(format_args.get(0));
+
+  using CharT = typename Context::char_type;
+  using To = std::basic_string_view<CharT>;
+  using V = std::basic_string<CharT>;
+  auto result = std::visit_format_arg(
+      [v = V(value.begin(), value.end())](auto a) -> To {
+        if constexpr (std::is_same_v<To, decltype(a)>) {
+          assert(v == a);
+          return a;
+        } else {
+          assert(false);
+          return {};
+        }
+      },
+      format_args.get(0));
+
+  assert(std::equal(value.begin(), value.end(), result.begin(), result.end()));
+}
+
+template <class CharT>
+void test() {
+  using Context = std::basic_format_context<CharT*, CharT>;
+  std::basic_string<CharT> empty;
+  std::basic_string<CharT> str = MAKE_STRING(CharT, "abc");
+
+  // Test boolean types.
+
+  test<Context, bool>(true);
+  test<Context, bool>(false);
+
+  // Test CharT types.
+
+  test<Context, CharT, CharT>('a');
+  test<Context, CharT, CharT>('z');
+  test<Context, CharT, CharT>('0');
+  test<Context, CharT, CharT>('9');
+
+  // Test char types.
+
+  if (std::is_same_v<CharT, char>) {
+    // char to char -> char
+    test<Context, CharT, char>('a');
+    test<Context, CharT, char>('z');
+    test<Context, CharT, char>('0');
+    test<Context, CharT, char>('9');
+  } else {
+    if (std::is_same_v<CharT, wchar_t>) {
+      // char to wchar_t -> wchar_t
+      test<Context, wchar_t, char>('a');
+      test<Context, wchar_t, char>('z');
+      test<Context, wchar_t, char>('0');
+      test<Context, wchar_t, char>('9');
+    } else if (std::is_signed_v<char>) {
+      // char to CharT -> int
+      // This happens when CharT is a char8_t, char16_t, or char32_t and char
+      // is a signed type.
+      // Note if sizeof(CharT) > sizeof(int) this test fails. If there are
+      // platforms where that occurs extra tests need to be added for char32_t
+      // testing it against a long long.
+      test<Context, int, char>('a');
+      test<Context, int, char>('z');
+      test<Context, int, char>('0');
+      test<Context, int, char>('9');
+    } else {
+      // char to CharT -> unsigned
+      // This happens when CharT is a char8_t, char16_t, or char32_t and char
+      // is an unsigned type.
+      // Note if sizeof(CharT) > sizeof(unsigned) this test fails. If there are
+      // platforms where that occurs extra tests need to be added for char32_t
+      // testing it against an unsigned long long.
+      test<Context, unsigned, char>('a');
+      test<Context, unsigned, char>('z');
+      test<Context, unsigned, char>('0');
+      test<Context, unsigned, char>('9');
+    }
+  }
+
+  // Test signed integer types.
+
+  test<Context, int, signed char>(std::numeric_limits<signed char>::min());
+  test<Context, int, signed char>(0);
+  test<Context, int, signed char>(std::numeric_limits<signed char>::max());
+
+  test<Context, int, short>(std::numeric_limits<short>::min());
+  test<Context, int, short>(std::numeric_limits<signed char>::min());
+  test<Context, int, short>(0);
+  test<Context, int, short>(std::numeric_limits<signed char>::max());
+  test<Context, int, short>(std::numeric_limits<short>::max());
+
+  test<Context, int, int>(std::numeric_limits<int>::min());
+  test<Context, int, int>(std::numeric_limits<short>::min());
+  test<Context, int, int>(std::numeric_limits<signed char>::min());
+  test<Context, int, int>(0);
+  test<Context, int, int>(std::numeric_limits<signed char>::max());
+  test<Context, int, int>(std::numeric_limits<short>::max());
+  test<Context, int, int>(std::numeric_limits<int>::max());
+
+  using LongToType =
+      std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
+
+  test<Context, LongToType, long>(std::numeric_limits<long>::min());
+  test<Context, LongToType, long>(std::numeric_limits<int>::min());
+  test<Context, LongToType, long>(std::numeric_limits<short>::min());
+  test<Context, LongToType, long>(std::numeric_limits<signed char>::min());
+  test<Context, LongToType, long>(0);
+  test<Context, LongToType, long>(std::numeric_limits<signed char>::max());
+  test<Context, LongToType, long>(std::numeric_limits<short>::max());
+  test<Context, LongToType, long>(std::numeric_limits<int>::max());
+  test<Context, LongToType, long>(std::numeric_limits<long>::max());
+
+  test<Context, long long, long long>(std::numeric_limits<long long>::min());
+  test<Context, long long, long long>(std::numeric_limits<long>::min());
+  test<Context, long long, long long>(std::numeric_limits<int>::min());
+  test<Context, long long, long long>(std::numeric_limits<short>::min());
+  test<Context, long long, long long>(std::numeric_limits<signed char>::min());
+  test<Context, long long, long long>(0);
+  test<Context, long long, long long>(std::numeric_limits<signed char>::max());
+  test<Context, long long, long long>(std::numeric_limits<short>::max());
+  test<Context, long long, long long>(std::numeric_limits<int>::max());
+  test<Context, long long, long long>(std::numeric_limits<long>::max());
+  test<Context, long long, long long>(std::numeric_limits<long long>::max());
+
+#ifndef TEST_HAS_NO_INT128
+  test_handle<Context, __int128_t>(0);
+#endif // TEST_HAS_NO_INT128
+
+  // Test unsigned integer types.
+
+  test<Context, unsigned, unsigned char>(0);
+  test<Context, unsigned, unsigned char>(
+      std::numeric_limits<unsigned char>::max());
+
+  test<Context, unsigned, unsigned short>(0);
+  test<Context, unsigned, unsigned short>(
+      std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned short>(
+      std::numeric_limits<unsigned short>::max());
+
+  test<Context, unsigned, unsigned>(0);
+  test<Context, unsigned, unsigned>(std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned>(std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned, unsigned>(std::numeric_limits<unsigned>::max());
+
+  using UnsignedLongToType =
+      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned,
+                         unsigned long long>;
+
+  test<Context, UnsignedLongToType, unsigned long>(0);
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned char>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned short>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned long>::max());
+
+  test<Context, unsigned long long, unsigned long long>(0);
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned long>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned long long>::max());
+
+#ifndef TEST_HAS_NO_INT128
+  test_handle<Context, __uint128_t>(0);
+#endif // TEST_HAS_NO_INT128
+
+  // Test floating point types.
+
+  test<Context, float, float>(-std::numeric_limits<float>::max());
+  test<Context, float, float>(-std::numeric_limits<float>::min());
+  test<Context, float, float>(-0.0);
+  test<Context, float, float>(0.0);
+  test<Context, float, float>(std::numeric_limits<float>::min());
+  test<Context, float, float>(std::numeric_limits<float>::max());
+
+  test<Context, double, double>(-std::numeric_limits<double>::max());
+  test<Context, double, double>(-std::numeric_limits<double>::min());
+  test<Context, double, double>(-0.0);
+  test<Context, double, double>(0.0);
+  test<Context, double, double>(std::numeric_limits<double>::min());
+  test<Context, double, double>(std::numeric_limits<double>::max());
+
+  test<Context, long double, long double>(
+      -std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(
+      -std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(-0.0);
+  test<Context, long double, long double>(0.0);
+  test<Context, long double, long double>(
+      std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(
+      std::numeric_limits<long double>::max());
+
+  // Test const CharT pointer types.
+
+  test<Context, const CharT*, const CharT*>(empty.c_str());
+  test<Context, const CharT*, const CharT*>(str.c_str());
+
+  // Test string_view types.
+
+  {
+    using From = std::basic_string_view<CharT>;
+
+    test_string_view<Context>(From());
+    test_string_view<Context>(From(empty.c_str()));
+    test_string_view<Context>(From(str.c_str()));
+  }
+
+  {
+    using From = std::basic_string_view<CharT, constexpr_char_traits<CharT>>;
+
+    test_string_view<Context>(From());
+    test_string_view<Context>(From(empty.c_str()));
+    test_string_view<Context>(From(str.c_str()));
+  }
+
+  // Test string types.
+
+  {
+    using From = std::basic_string<CharT>;
+
+    test_string_view<Context>(From());
+    test_string_view<Context>(From(empty.c_str()));
+    test_string_view<Context>(From(str.c_str()));
+  }
+
+  {
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>,
+                                   std::allocator<CharT>>;
+
+    test_string_view<Context>(From());
+    test_string_view<Context>(From(empty.c_str()));
+    test_string_view<Context>(From(str.c_str()));
+  }
+
+  {
+    using From =
+        std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
+
+    test_string_view<Context>(From());
+    test_string_view<Context>(From(empty.c_str()));
+    test_string_view<Context>(From(str.c_str()));
+  }
+
+  {
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>,
+                                   min_allocator<CharT>>;
+
+    test_string_view<Context>(From());
+    test_string_view<Context>(From(empty.c_str()));
+    test_string_view<Context>(From(str.c_str()));
+  }
+
+  // Test pointer types.
+
+  test<Context, const void*>(nullptr);
+  int i = 0;
+  test<Context, const void*>(static_cast<void*>(&i));
+  const int ci = 0;
+  test<Context, const void*>(static_cast<const void*>(&ci));
+}
+
+int main(int, char**) {
+  test<char>();
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
+  test<wchar_t>();
+#endif
+
+  return 0;
+}
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index fbd01f8de15962..cdbeefd1424362 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -467,7 +467,7 @@ def add_version_header(tc):
                 # "c++20": 202110 Not implemented P2372R3 Fixing locale handling in chrono formatters
                 "c++20": 202106,
                 # "c++23": 202207, Not implemented P2419R2 Clarify handling of encodings in localized formatting of chrono types
-                # "c++26": 202306, # P2637R3 Member Visit
+                # "c++26": 202306, P2637R3 Member Visit (implemented)
                 # "c++26": 202311, P2918R2 Runtime format strings II (implemented)
             },
             # Note these three papers are adopted at the June 2023 meeting and have sequential numbering

>From 9301ae02f50688bd57973f717a074d8286b8d2a9 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Fri, 29 Dec 2023 18:26:22 +0200
Subject: [PATCH 09/29] Addressed comments

---
 .../format.arg/visit.pass.cpp                 | 53 +++++--------------
 .../visit_format_arg.deprecated.verify.cpp    | 50 +++--------------
 2 files changed, 18 insertions(+), 85 deletions(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
index c3b1609c159c8d..3b4c847dfc3579 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
@@ -5,7 +5,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 
 // <format>
@@ -15,9 +15,6 @@
 // template<class Visitor>
 //   decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);  // since C++26
 
-// template<class Visitor, class Context>
-//   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // deprecated in C++26
-
 #include <algorithm>
 #include <cassert>
 #include <format>
@@ -28,9 +25,6 @@
 #include "min_allocator.h"
 #include "test_macros.h"
 
-// Deprecated `std::visit_format_arg` should be tested in C++26 or newer.
-TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
-
 template <class Context, class To, class From>
 void test(From value) {
   auto store = std::make_format_args<Context>(value);
@@ -39,41 +33,18 @@ void test(From value) {
   LIBCPP_ASSERT(format_args.__size() == 1);
   assert(format_args.get(0));
 
-#if _LIBCPP_STD_VER >= 26
-  // member
-  {
-    auto result = format_args.get(0).visit([v = To(value)](auto a) -> To {
-      if constexpr (std::is_same_v<To, decltype(a)>) {
-        assert(v == a);
-        return a;
-      } else {
-        assert(false);
-        return {};
-      }
-    });
-
-    using ct = std::common_type_t<From, To>;
-    assert(static_cast<ct>(result) == static_cast<ct>(value));
-  }
-#endif
+  auto result = format_args.get(0).visit([v = To(value)](auto a) -> To {
+    if constexpr (std::is_same_v<To, decltype(a)>) {
+      assert(v == a);
+      return a;
+    } else {
+      assert(false);
+      return {};
+    }
+  });
 
-  // non-member
-  {
-    auto result = std::visit_format_arg(
-        [v = To(value)](auto a) -> To {
-          if constexpr (std::is_same_v<To, decltype(a)>) {
-            assert(v == a);
-            return a;
-          } else {
-            assert(false);
-            return {};
-          }
-        },
-        format_args.get(0));
-
-    using ct = std::common_type_t<From, To>;
-    assert(static_cast<ct>(result) == static_cast<ct>(value));
-  }
+  using ct = std::common_type_t<From, To>;
+  assert(static_cast<ct>(result) == static_cast<ct>(value));
 }
 
 // Some types, as an extension, are stored in the variant. The Standard
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
index 2e23b88871b681..2a886a1cbc1818 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
@@ -13,52 +13,14 @@
 // template<class Visitor, class Context>
 //   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
 
-#include <algorithm>
-#include <cassert>
 #include <format>
-#include <type_traits>
 
-#include "constexpr_char_traits.h"
-#include "make_string.h"
-#include "min_allocator.h"
-#include "test_macros.h"
-
-template <class Context, class To, class From>
-void test(From value) {
-  auto store = std::make_format_args<Context>(value);
-  std::basic_format_args<Context> format_args{store};
-
-  LIBCPP_ASSERT(format_args.__size() == 1);
-  assert(format_args.get(0));
-
-  // non-member
-  {
-    // expected-warning at +1 {{std::basic_format_context<char *, char>>' is deprecated}}
-    std::visit_format_arg(
-        [v = To(value)](auto a) -> To {
-          if constexpr (std::is_same_v<To, decltype(a)>) {
-            assert(v == a);
-            return a;
-          } else {
-            assert(false);
-            return {};
-          }
-        },
-        format_args.get(0));
-  }
-}
-
-template <class CharT>
 void test() {
-  using Context = std::basic_format_context<CharT*, CharT>;
-  std::basic_string<CharT> empty;
-  std::basic_string<CharT> str = MAKE_STRING(CharT, "abc");
-
-  test<Context, bool>(true);
-}
-
-int main(int, char**) {
-  test<char>();
+  // expected-warning at +1 {{std::basic_format_context<char *, char>>' is deprecated}}
+  std::visit_format_arg([]([[maybe_unused]] auto a) -> char { return {}; },
+                        std::basic_format_arg<std::basic_format_context<char*, char>>{});
 
-  return 0;
+  // expected-warning at +1 {{std::basic_format_context<wchar_t *, wchar_t>>' is deprecated}}
+  std::visit_format_arg([]([[maybe_unused]] auto a) -> wchar_t { return {}; },
+                        std::basic_format_arg<std::basic_format_context<wchar_t*, wchar_t>>{});
 }

>From 7f7c0c17a8d503c4cc051eedb820f2608aa7380f Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Fri, 29 Dec 2023 18:45:21 +0200
Subject: [PATCH 10/29] Fixed tests

---
 .../format.arg/visit.pass.cpp                 | 31 ++++----
 .../format.arg/visit_format_arg.pass.cpp      | 75 +++++++------------
 2 files changed, 44 insertions(+), 62 deletions(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
index 3b4c847dfc3579..5df002a5c87b0d 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
@@ -57,9 +57,9 @@ void test_handle(T value) {
   LIBCPP_ASSERT(format_args.__size() == 1);
   assert(format_args.get(0));
 
-  std::visit_format_arg(
-      [](auto a) { assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>)); },
-      format_args.get(0));
+  format_args.get(0).visit([](auto a) {
+    assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>));
+  });
 }
 
 // Test specific for string and string_view.
@@ -77,17 +77,16 @@ void test_string_view(From value) {
   using CharT = typename Context::char_type;
   using To    = std::basic_string_view<CharT>;
   using V     = std::basic_string<CharT>;
-  auto result = std::visit_format_arg(
-      [v = V(value.begin(), value.end())](auto a) -> To {
-        if constexpr (std::is_same_v<To, decltype(a)>) {
-          assert(v == a);
-          return a;
-        } else {
-          assert(false);
-          return {};
-        }
-      },
-      format_args.get(0));
+
+  auto result = format_args.get(0).visit([v = V(value.begin(), value.end())](auto a) -> To {
+    if constexpr (std::is_same_v<To, decltype(a)>) {
+      assert(v == a);
+      return a;
+    } else {
+      assert(false);
+      return {};
+    }
+  });
 
   assert(std::equal(value.begin(), value.end(), result.begin(), result.end()));
 }
@@ -195,7 +194,7 @@ void test() {
   test<Context, long long, long long>(std::numeric_limits<long long>::max());
 
 #ifndef TEST_HAS_NO_INT128
-  test_handle<Context, __int128_t>(0);
+  // test_handle<Context, __int128_t>(0);
 #endif // TEST_HAS_NO_INT128
 
   // Test unsigned integer types.
@@ -229,7 +228,7 @@ void test() {
   test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long long>::max());
 
 #ifndef TEST_HAS_NO_INT128
-  test_handle<Context, __uint128_t>(0);
+  // test_handle<Context, __uint128_t>(0);
 #endif // TEST_HAS_NO_INT128
 
   // Test floating point types.
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
index 3ddf2d0ff732a7..38aaca3c015372 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
@@ -14,14 +14,18 @@
 //   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
 
 #include <algorithm>
-#include <format>
 #include <cassert>
+#include <format>
 #include <type_traits>
 
 #include "constexpr_char_traits.h"
-#include "test_macros.h"
 #include "make_string.h"
 #include "min_allocator.h"
+#include "test_macros.h"
+
+#if _LIBCPP_STD_VER >= 26
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+#endif
 
 template <class Context, class To, class From>
 void test(From value) {
@@ -75,8 +79,8 @@ void test_string_view(From value) {
   assert(format_args.get(0));
 
   using CharT = typename Context::char_type;
-  using To = std::basic_string_view<CharT>;
-  using V = std::basic_string<CharT>;
+  using To    = std::basic_string_view<CharT>;
+  using V     = std::basic_string<CharT>;
   auto result = std::visit_format_arg(
       [v = V(value.begin(), value.end())](auto a) -> To {
         if constexpr (std::is_same_v<To, decltype(a)>) {
@@ -170,8 +174,7 @@ void test() {
   test<Context, int, int>(std::numeric_limits<short>::max());
   test<Context, int, int>(std::numeric_limits<int>::max());
 
-  using LongToType =
-      std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
+  using LongToType = std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
 
   test<Context, LongToType, long>(std::numeric_limits<long>::min());
   test<Context, LongToType, long>(std::numeric_limits<int>::min());
@@ -202,14 +205,11 @@ void test() {
   // Test unsigned integer types.
 
   test<Context, unsigned, unsigned char>(0);
-  test<Context, unsigned, unsigned char>(
-      std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned char>(std::numeric_limits<unsigned char>::max());
 
   test<Context, unsigned, unsigned short>(0);
-  test<Context, unsigned, unsigned short>(
-      std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned, unsigned short>(
-      std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned short>::max());
 
   test<Context, unsigned, unsigned>(0);
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned char>::max());
@@ -217,30 +217,20 @@ void test() {
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned>::max());
 
   using UnsignedLongToType =
-      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned,
-                         unsigned long long>;
+      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned, unsigned long long>;
 
   test<Context, UnsignedLongToType, unsigned long>(0);
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned char>::max());
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned short>::max());
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned>::max());
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned long>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned char>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned short>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned long>::max());
 
   test<Context, unsigned long long, unsigned long long>(0);
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned short>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned long>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned long long>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long long>::max());
 
 #ifndef TEST_HAS_NO_INT128
   test_handle<Context, __uint128_t>(0);
@@ -262,16 +252,12 @@ void test() {
   test<Context, double, double>(std::numeric_limits<double>::min());
   test<Context, double, double>(std::numeric_limits<double>::max());
 
-  test<Context, long double, long double>(
-      -std::numeric_limits<long double>::max());
-  test<Context, long double, long double>(
-      -std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(-std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(-std::numeric_limits<long double>::min());
   test<Context, long double, long double>(-0.0);
   test<Context, long double, long double>(0.0);
-  test<Context, long double, long double>(
-      std::numeric_limits<long double>::min());
-  test<Context, long double, long double>(
-      std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(std::numeric_limits<long double>::max());
 
   // Test const CharT pointer types.
 
@@ -307,8 +293,7 @@ void test() {
   }
 
   {
-    using From = std::basic_string<CharT, constexpr_char_traits<CharT>,
-                                   std::allocator<CharT>>;
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>, std::allocator<CharT>>;
 
     test_string_view<Context>(From());
     test_string_view<Context>(From(empty.c_str()));
@@ -316,8 +301,7 @@ void test() {
   }
 
   {
-    using From =
-        std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
+    using From = std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
 
     test_string_view<Context>(From());
     test_string_view<Context>(From(empty.c_str()));
@@ -325,8 +309,7 @@ void test() {
   }
 
   {
-    using From = std::basic_string<CharT, constexpr_char_traits<CharT>,
-                                   min_allocator<CharT>>;
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>, min_allocator<CharT>>;
 
     test_string_view<Context>(From());
     test_string_view<Context>(From(empty.c_str()));

>From ede04db18742af44d175df6eb61c825e3522e4cb Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Fri, 29 Dec 2023 20:36:15 +0200
Subject: [PATCH 11/29] Added missing test cases

---
 .../format.arg/visit.pass.cpp                 |  8 ++--
 .../format.arg/visit.return_type.pass.cpp     | 42 +++++++++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
index 5df002a5c87b0d..d5486eddca8030 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
@@ -58,7 +58,9 @@ void test_handle(T value) {
   assert(format_args.get(0));
 
   format_args.get(0).visit([](auto a) {
-    assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>));
+    // TODO: This assertion fails
+    (void) a;
+    // assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>));
   });
 }
 
@@ -194,7 +196,7 @@ void test() {
   test<Context, long long, long long>(std::numeric_limits<long long>::max());
 
 #ifndef TEST_HAS_NO_INT128
-  // test_handle<Context, __int128_t>(0);
+  test_handle<Context, __int128_t>(0);
 #endif // TEST_HAS_NO_INT128
 
   // Test unsigned integer types.
@@ -228,7 +230,7 @@ void test() {
   test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long long>::max());
 
 #ifndef TEST_HAS_NO_INT128
-  // test_handle<Context, __uint128_t>(0);
+  test_handle<Context, __uint128_t>(0);
 #endif // TEST_HAS_NO_INT128
 
   // Test floating point types.
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
index 470df35ef97196..1cf2eb5ed9144e 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
@@ -224,6 +224,48 @@ void test() {
   test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<long>::max(), visited);
   test<Context, long long, ExpectedResultType, long long>(std::numeric_limits<long long>::max(), visited);
 
+#ifndef TEST_HAS_NO_INT128
+  test_handle<Context, __int128_t, ExpectedResultType>(0, visited);
+#endif // TEST_HAS_NO_INT128
+
+  // Test unsigned integer types.
+
+  test<Context, unsigned, ExpectedResultType, unsigned char>(0, visited);
+  test<Context, unsigned, ExpectedResultType, unsigned char>(std::numeric_limits<unsigned char>::max(), visited);
+
+  test<Context, unsigned, ExpectedResultType, unsigned short>(0, visited);
+  test<Context, unsigned, ExpectedResultType, unsigned short>(std::numeric_limits<unsigned char>::max(), visited);
+  test<Context, unsigned, ExpectedResultType, unsigned short>(std::numeric_limits<unsigned short>::max(), visited);
+
+  test<Context, unsigned, ExpectedResultType, unsigned>(0, visited);
+  test<Context, unsigned, ExpectedResultType, unsigned>(std::numeric_limits<unsigned char>::max(), visited);
+  test<Context, unsigned, ExpectedResultType, unsigned>(std::numeric_limits<unsigned short>::max(), visited);
+  test<Context, unsigned, ExpectedResultType, unsigned>(std::numeric_limits<unsigned>::max(), visited);
+
+  using UnsignedLongToType =
+      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned, unsigned long long>;
+
+  test<Context, UnsignedLongToType, ExpectedResultType, unsigned long>(0, visited);
+  test<Context, UnsignedLongToType, ExpectedResultType, unsigned long>(
+      std::numeric_limits<unsigned char>::max(), visited);
+  test<Context, UnsignedLongToType, ExpectedResultType, unsigned long>(
+      std::numeric_limits<unsigned short>::max(), visited);
+  test<Context, UnsignedLongToType, ExpectedResultType, unsigned long>(std::numeric_limits<unsigned>::max(), visited);
+  test<Context, UnsignedLongToType, ExpectedResultType, unsigned long>(
+      std::numeric_limits<unsigned long>::max(), visited);
+
+  test<Context, unsigned long long, ExpectedResultType, unsigned long long>(0, visited);
+  test<Context, unsigned long long, ExpectedResultType, unsigned long long>(
+      std::numeric_limits<unsigned char>::max(), visited);
+  test<Context, unsigned long long, ExpectedResultType, unsigned long long>(
+      std::numeric_limits<unsigned short>::max(), visited);
+  test<Context, unsigned long long, ExpectedResultType, unsigned long long>(
+      std::numeric_limits<unsigned>::max(), visited);
+  test<Context, unsigned long long, ExpectedResultType, unsigned long long>(
+      std::numeric_limits<unsigned long>::max(), visited);
+  test<Context, unsigned long long, ExpectedResultType, unsigned long long>(
+      std::numeric_limits<unsigned long long>::max(), visited);
+
 #ifndef TEST_HAS_NO_INT128
   test_handle<Context, __uint128_t, ExpectedResultType>(0, visited);
 #endif // TEST_HAS_NO_INT128

>From 30ee407b6c62041192780dbac26683c28cab8de8 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Fri, 29 Dec 2023 21:05:51 +0200
Subject: [PATCH 12/29] Fixed implementation of `__int128/__uint128`

---
 libcxx/include/__format/format_arg.h          | 32 +++++++++++++++++--
 .../format.arg/visit.pass.cpp                 |  4 +--
 .../format.arg/visit.return_type.pass.cpp     |  4 +--
 3 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index bc9e13eb9029a5..6d4a20201e165a 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -281,12 +281,40 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
 #  if _LIBCPP_STD_VER >= 26
   template <class _Visitor>
   _LIBCPP_HIDE_FROM_ABI decltype(auto) visit(this basic_format_arg __arg, _Visitor&& __vis) {
-    return std::__visit_format_arg(std::forward<_Visitor>(__vis), __arg);
+    switch (__arg.__type_) {
+#    ifndef _LIBCPP_HAS_NO_INT128
+    case __format::__arg_t::__i128: {
+      typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_};
+      return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
+    }
+
+    case __format::__arg_t::__u128: {
+      typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_};
+      return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
+    }
+#    endif
+    default:
+      return std::__visit_format_arg(std::forward<_Visitor>(__vis), __arg);
+    }
   }
 
   template <class _Rp, class _Visitor>
   _LIBCPP_HIDE_FROM_ABI _Rp visit(this basic_format_arg __arg, _Visitor&& __vis) {
-    return std::__visit_format_arg<_Rp>(std::forward<_Visitor>(__vis), __arg);
+    switch (__arg.__type_) {
+#    ifndef _LIBCPP_HAS_NO_INT128
+    case __format::__arg_t::__i128: {
+      typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_};
+      return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
+    }
+
+    case __format::__arg_t::__u128: {
+      typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_};
+      return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
+    }
+#    endif
+    default:
+      return std::__visit_format_arg<_Rp>(std::forward<_Visitor>(__vis), __arg);
+    }
   }
 #  endif
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
index d5486eddca8030..84c5e059701420 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
@@ -58,9 +58,7 @@ void test_handle(T value) {
   assert(format_args.get(0));
 
   format_args.get(0).visit([](auto a) {
-    // TODO: This assertion fails
-    (void) a;
-    // assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>));
+    assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>));
   });
 }
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
index 1cf2eb5ed9144e..986ecb174eb78f 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
@@ -76,9 +76,7 @@ void test_handle(T value, ExpectedR expectedValue) {
   assert(format_args.get(0));
 
   std::same_as<ExpectedR> decltype(auto) result = format_args.get(0).template visit<ExpectedR>([](auto a) -> ExpectedR {
-    // TODO: This check fails
-    (void)a;
-    // assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>));
+    assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>));
 
     return make_expected_result<ExpectedR>();
   });

>From 94aa9c022dfcde597f2bdfa3df97c615f0fd53b7 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sat, 30 Dec 2023 07:48:21 +0200
Subject: [PATCH 13/29] Fixed deprecation warning errors

---
 libcxx/include/__format/format_context.h      |  31 +++--
 .../format.arguments/format.args/get.pass.cpp | 123 ++++++++----------
 libcxx/test/support/test_basic_format_arg.h   |  20 +--
 3 files changed, 83 insertions(+), 91 deletions(-)

diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index 5b252b81f691bc..98b8f0d6329fb4 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -163,20 +163,23 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
 #  endif
         __ctx_(std::addressof(__ctx)),
         __arg_([](void* __c, size_t __id) {
-          return std::visit_format_arg(
-              [&](auto __arg) -> basic_format_arg<basic_format_context> {
-                if constexpr (same_as<decltype(__arg), monostate>)
-                  return {};
-                else if constexpr (same_as<decltype(__arg), typename basic_format_arg<_Context>::handle>)
-                  // At the moment it's not possible for formatting to use a re-targeted handle.
-                  // TODO FMT add this when support is needed.
-                  std::__throw_format_error("Re-targeting handle not supported");
-                else
-                  return basic_format_arg<basic_format_context>{
-                      __format::__determine_arg_t<basic_format_context, decltype(__arg)>(),
-                      __basic_format_arg_value<basic_format_context>(__arg)};
-              },
-              static_cast<_Context*>(__c)->arg(__id));
+          auto visitor = [&](auto __arg) -> basic_format_arg<basic_format_context> {
+            if constexpr (same_as<decltype(__arg), monostate>)
+              return {};
+            else if constexpr (same_as<decltype(__arg), typename basic_format_arg<_Context>::handle>)
+              // At the moment it's not possible for formatting to use a re-targeted handle.
+              // TODO FMT add this when support is needed.
+              std::__throw_format_error("Re-targeting handle not supported");
+            else
+              return basic_format_arg<basic_format_context>{
+                  __format::__determine_arg_t<basic_format_context, decltype(__arg)>(),
+                  __basic_format_arg_value<basic_format_context>(__arg)};
+          };
+#  if _LIBCPP_STD_VER >= 26
+          return static_cast<_Context*>(__c)->arg(__id).visit(std::move(visitor));
+#  else
+          return std::visit_format_arg(std::move(visitor), static_cast<_Context*>(__c)->arg(__id));
+#  endif
         }) {
   }
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
index 0f3931adf54dfb..c72b0c7f593e41 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
@@ -24,14 +24,17 @@ void test(From value) {
   auto store = std::make_format_args<Context>(value);
   const std::basic_format_args<Context> format_args{store};
 
-  std::visit_format_arg(
-      [v = To(value)](auto a) {
-        if constexpr (std::is_same_v<To, decltype(a)>)
-          assert(v == a);
-        else
-          assert(false);
-      },
-      format_args.get(0));
+  auto visitor = [v = To(value)](auto a) {
+    if constexpr (std::is_same_v<To, decltype(a)>)
+      assert(v == a);
+    else
+      assert(false);
+  };
+
+#if _LIBCPP_STD_VER >= 26
+  format_args.get(0).visit(visitor);
+#endif
+  std::visit_format_arg(visitor, format_args.get(0));
 }
 
 // Some types, as an extension, are stored in the variant. The Standard
@@ -41,9 +44,12 @@ void test_handle(T value) {
   auto store = std::make_format_args<Context>(value);
   std::basic_format_args<Context> format_args{store};
 
-  std::visit_format_arg(
-      [](auto a) { assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>)); },
-      format_args.get(0));
+  auto visitor = [](auto a) { assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>)); };
+#if _LIBCPP_STD_VER >= 26
+  format_args.get(0).visit(visitor);
+#else
+  std::visit_format_arg(visitor, format_args.get(0));
+#endif
 }
 
 // Test specific for string and string_view.
@@ -56,16 +62,19 @@ void test_string_view(From value) {
   const std::basic_format_args<Context> format_args{store};
 
   using CharT = typename Context::char_type;
-  using To = std::basic_string_view<CharT>;
-  using V = std::basic_string<CharT>;
-  std::visit_format_arg(
-      [v = V(value.begin(), value.end())](auto a) {
-        if constexpr (std::is_same_v<To, decltype(a)>)
-          assert(v == a);
-        else
-          assert(false);
-      },
-      format_args.get(0));
+  using To    = std::basic_string_view<CharT>;
+  using V     = std::basic_string<CharT>;
+
+  auto visitor = [v = V(value.begin(), value.end())](auto a) {
+    if constexpr (std::is_same_v<To, decltype(a)>)
+      assert(v == a);
+    else
+      assert(false);
+  };
+#if _LIBCPP_STD_VER >= 26
+  format_args.get(0).visit(visitor);
+#endif
+  std::visit_format_arg(visitor, format_args.get(0));
 }
 
 template <class CharT>
@@ -153,8 +162,7 @@ void test() {
   test<Context, int, int>(std::numeric_limits<short>::max());
   test<Context, int, int>(std::numeric_limits<int>::max());
 
-  using LongToType =
-      std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
+  using LongToType = std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
 
   test<Context, LongToType, long>(std::numeric_limits<long>::min());
   test<Context, LongToType, long>(std::numeric_limits<int>::min());
@@ -185,14 +193,11 @@ void test() {
   // Test unsigned integer types.
 
   test<Context, unsigned, unsigned char>(0);
-  test<Context, unsigned, unsigned char>(
-      std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned char>(std::numeric_limits<unsigned char>::max());
 
   test<Context, unsigned, unsigned short>(0);
-  test<Context, unsigned, unsigned short>(
-      std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned, unsigned short>(
-      std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned short>::max());
 
   test<Context, unsigned, unsigned>(0);
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned char>::max());
@@ -200,30 +205,20 @@ void test() {
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned>::max());
 
   using UnsignedLongToType =
-      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned,
-                         unsigned long long>;
+      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned, unsigned long long>;
 
   test<Context, UnsignedLongToType, unsigned long>(0);
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned char>::max());
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned short>::max());
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned>::max());
-  test<Context, UnsignedLongToType, unsigned long>(
-      std::numeric_limits<unsigned long>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned char>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned short>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned>::max());
+  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned long>::max());
 
   test<Context, unsigned long long, unsigned long long>(0);
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned short>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned long>::max());
-  test<Context, unsigned long long, unsigned long long>(
-      std::numeric_limits<unsigned long long>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long>::max());
+  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long long>::max());
 
 #ifndef TEST_HAS_NO_INT128
   test_handle<Context, __uint128_t>(0);
@@ -245,16 +240,12 @@ void test() {
   test<Context, double, double>(std::numeric_limits<double>::min());
   test<Context, double, double>(std::numeric_limits<double>::max());
 
-  test<Context, long double, long double>(
-      -std::numeric_limits<long double>::max());
-  test<Context, long double, long double>(
-      -std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(-std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(-std::numeric_limits<long double>::min());
   test<Context, long double, long double>(-0.0);
   test<Context, long double, long double>(0.0);
-  test<Context, long double, long double>(
-      std::numeric_limits<long double>::min());
-  test<Context, long double, long double>(
-      std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(std::numeric_limits<long double>::max());
 
   // Test const char_type pointer types.
 
@@ -263,21 +254,15 @@ void test() {
 
   // Test string_view types.
 
-  test<Context, std::basic_string_view<char_type>>(
-      std::basic_string_view<char_type>());
-  test<Context, std::basic_string_view<char_type>,
-       std::basic_string_view<char_type>>(empty);
-  test<Context, std::basic_string_view<char_type>,
-       std::basic_string_view<char_type>>(str);
+  test<Context, std::basic_string_view<char_type>>(std::basic_string_view<char_type>());
+  test<Context, std::basic_string_view<char_type>, std::basic_string_view<char_type>>(empty);
+  test<Context, std::basic_string_view<char_type>, std::basic_string_view<char_type>>(str);
 
   // Test string types.
 
-  test<Context, std::basic_string_view<char_type>>(
-      std::basic_string<char_type>());
-  test<Context, std::basic_string_view<char_type>,
-       std::basic_string<char_type>>(empty);
-  test<Context, std::basic_string_view<char_type>,
-       std::basic_string<char_type>>(str);
+  test<Context, std::basic_string_view<char_type>>(std::basic_string<char_type>());
+  test<Context, std::basic_string_view<char_type>, std::basic_string<char_type>>(empty);
+  test<Context, std::basic_string_view<char_type>, std::basic_string<char_type>>(str);
 
   // Test pointer types.
 
diff --git a/libcxx/test/support/test_basic_format_arg.h b/libcxx/test/support/test_basic_format_arg.h
index d8547d34b6db43..91109e3a2d09f3 100644
--- a/libcxx/test/support/test_basic_format_arg.h
+++ b/libcxx/test/support/test_basic_format_arg.h
@@ -7,18 +7,22 @@
 
 #include <concepts>
 #include <format>
+#include <utility>
 
 #include "test_macros.h"
 
 /// Returns whether the basic_format_arg contains a type T with the expected value.
 template <class Context, class T>
 bool test_basic_format_arg(std::basic_format_arg<Context> arg, T expected) {
-  return std::visit_format_arg(
-      [expected](auto a) {
-        if constexpr (std::same_as<decltype(a), T>)
-          return a == expected;
-        else
-          return false;
-      },
-      arg);
+  auto visitor = [expected](auto a) {
+    if constexpr (std::same_as<decltype(a), T>)
+      return a == expected;
+    else
+      return false;
+  };
+#if _LIBCPP_STD_VER >= 26
+  return arg.visit(std::move(visitor));
+#else
+  return std::visit_format_arg(std::move(visitor), arg);
+#endif
 }

>From 1ee4bde5bb9b132ac4e34ebdf77a841c397bd73e Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sat, 30 Dec 2023 07:58:53 +0200
Subject: [PATCH 14/29] Fixed get.pass.cpp test

---
 .../format/format.arguments/format.args/get.pass.cpp          | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
index c72b0c7f593e41..2b228c7e519a3a 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
@@ -19,6 +19,10 @@
 #include "test_macros.h"
 #include "make_string.h"
 
+#if _LIBCPP_STD_VER >= 26
+TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+#endif
+
 template <class Context, class To, class From>
 void test(From value) {
   auto store = std::make_format_args<Context>(value);

>From eb0bc0bc9eebabe73b2150312a5897ab97202b57 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sun, 31 Dec 2023 09:43:33 +0200
Subject: [PATCH 15/29] Addressed comments

---
 libcxx/include/__format/format_arg.h                        | 4 ++++
 libcxx/include/__format/format_context.h                    | 6 +++---
 libcxx/include/format                                       | 2 +-
 .../format.arg/visit_format_arg.deprecated.verify.cpp       | 3 ++-
 .../format.arguments/format.arg/visit_format_arg.pass.cpp   | 2 +-
 5 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index 6d4a20201e165a..9d476d072bf741 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -279,6 +279,8 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
 
 #  if _LIBCPP_STD_VER >= 26
+  // This function is user facing, so it must wrap the non-standard types of
+  // the "variant" in a handle to stay conforming. See __arg_t for more details.
   template <class _Visitor>
   _LIBCPP_HIDE_FROM_ABI decltype(auto) visit(this basic_format_arg __arg, _Visitor&& __vis) {
     switch (__arg.__type_) {
@@ -298,6 +300,8 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
     }
   }
 
+  // This function is user facing, so it must wrap the non-standard types of
+  // the "variant" in a handle to stay conforming. See __arg_t for more details.
   template <class _Rp, class _Visitor>
   _LIBCPP_HIDE_FROM_ABI _Rp visit(this basic_format_arg __arg, _Visitor&& __vis) {
     switch (__arg.__type_) {
diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index 98b8f0d6329fb4..d35268634bfe60 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -163,7 +163,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
 #  endif
         __ctx_(std::addressof(__ctx)),
         __arg_([](void* __c, size_t __id) {
-          auto visitor = [&](auto __arg) -> basic_format_arg<basic_format_context> {
+          auto __visitor = [&](auto __arg) -> basic_format_arg<basic_format_context> {
             if constexpr (same_as<decltype(__arg), monostate>)
               return {};
             else if constexpr (same_as<decltype(__arg), typename basic_format_arg<_Context>::handle>)
@@ -176,9 +176,9 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
                   __basic_format_arg_value<basic_format_context>(__arg)};
           };
 #  if _LIBCPP_STD_VER >= 26
-          return static_cast<_Context*>(__c)->arg(__id).visit(std::move(visitor));
+          return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
 #  else
-          return std::visit_format_arg(std::move(visitor), static_cast<_Context*>(__c)->arg(__id));
+          return std::visit_format_arg(std::move(__visitor), static_cast<_Context*>(__c)->arg(__id));
 #  endif
         }) {
   }
diff --git a/libcxx/include/format b/libcxx/include/format
index e1566fb4636a7b..64f6ba1d25284a 100644
--- a/libcxx/include/format
+++ b/libcxx/include/format
@@ -170,7 +170,7 @@ namespace std {
   template<class Context> class basic_format_arg;
 
   template<class Visitor, class Context>
-    see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // deprecated in C++26
+    see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // Deprecated in C++26
 
   // [format.arg.store], class template format-arg-store
   template<class Context, class... Args> struct format-arg-store;      // exposition only
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
index 2a886a1cbc1818..4b8c7ff3c9c4b4 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
@@ -19,8 +19,9 @@ void test() {
   // expected-warning at +1 {{std::basic_format_context<char *, char>>' is deprecated}}
   std::visit_format_arg([]([[maybe_unused]] auto a) -> char { return {}; },
                         std::basic_format_arg<std::basic_format_context<char*, char>>{});
-
+#ifndef TEST_HAS_NO_WIDE_CHARACTERS
   // expected-warning at +1 {{std::basic_format_context<wchar_t *, wchar_t>>' is deprecated}}
   std::visit_format_arg([]([[maybe_unused]] auto a) -> wchar_t { return {}; },
                         std::basic_format_arg<std::basic_format_context<wchar_t*, wchar_t>>{});
+#endif
 }
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
index 38aaca3c015372..6c9248b80dec50 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
@@ -11,7 +11,7 @@
 // <format>
 
 // template<class Visitor, class Context>
-//   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
+//   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // Deprecated in C++26
 
 #include <algorithm>
 #include <cassert>

>From 6e85ab6b5918b10b75ed83b9ce5b5017f6409d6b Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sun, 31 Dec 2023 09:49:53 +0200
Subject: [PATCH 16/29] Restored original formatting

---
 .../format.arg/visit_format_arg.pass.cpp      | 71 ++++++++++++-------
 1 file changed, 46 insertions(+), 25 deletions(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
index 6c9248b80dec50..d4da9f92d9de73 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
@@ -14,14 +14,14 @@
 //   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg); // Deprecated in C++26
 
 #include <algorithm>
-#include <cassert>
 #include <format>
+#include <cassert>
 #include <type_traits>
 
 #include "constexpr_char_traits.h"
+#include "test_macros.h"
 #include "make_string.h"
 #include "min_allocator.h"
-#include "test_macros.h"
 
 #if _LIBCPP_STD_VER >= 26
 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
@@ -79,8 +79,8 @@ void test_string_view(From value) {
   assert(format_args.get(0));
 
   using CharT = typename Context::char_type;
-  using To    = std::basic_string_view<CharT>;
-  using V     = std::basic_string<CharT>;
+  using To = std::basic_string_view<CharT>;
+  using V = std::basic_string<CharT>;
   auto result = std::visit_format_arg(
       [v = V(value.begin(), value.end())](auto a) -> To {
         if constexpr (std::is_same_v<To, decltype(a)>) {
@@ -174,7 +174,8 @@ void test() {
   test<Context, int, int>(std::numeric_limits<short>::max());
   test<Context, int, int>(std::numeric_limits<int>::max());
 
-  using LongToType = std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
+  using LongToType =
+      std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
 
   test<Context, LongToType, long>(std::numeric_limits<long>::min());
   test<Context, LongToType, long>(std::numeric_limits<int>::min());
@@ -205,11 +206,14 @@ void test() {
   // Test unsigned integer types.
 
   test<Context, unsigned, unsigned char>(0);
-  test<Context, unsigned, unsigned char>(std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned char>(
+      std::numeric_limits<unsigned char>::max());
 
   test<Context, unsigned, unsigned short>(0);
-  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned, unsigned short>(
+      std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned short>(
+      std::numeric_limits<unsigned short>::max());
 
   test<Context, unsigned, unsigned>(0);
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned char>::max());
@@ -217,20 +221,30 @@ void test() {
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned>::max());
 
   using UnsignedLongToType =
-      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned, unsigned long long>;
+      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned,
+                         unsigned long long>;
 
   test<Context, UnsignedLongToType, unsigned long>(0);
-  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned char>::max());
-  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned short>::max());
-  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned>::max());
-  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned long>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned char>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned short>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned long>::max());
 
   test<Context, unsigned long long, unsigned long long>(0);
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned short>::max());
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned>::max());
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long>::max());
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long long>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned long>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned long long>::max());
 
 #ifndef TEST_HAS_NO_INT128
   test_handle<Context, __uint128_t>(0);
@@ -252,12 +266,16 @@ void test() {
   test<Context, double, double>(std::numeric_limits<double>::min());
   test<Context, double, double>(std::numeric_limits<double>::max());
 
-  test<Context, long double, long double>(-std::numeric_limits<long double>::max());
-  test<Context, long double, long double>(-std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(
+      -std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(
+      -std::numeric_limits<long double>::min());
   test<Context, long double, long double>(-0.0);
   test<Context, long double, long double>(0.0);
-  test<Context, long double, long double>(std::numeric_limits<long double>::min());
-  test<Context, long double, long double>(std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(
+      std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(
+      std::numeric_limits<long double>::max());
 
   // Test const CharT pointer types.
 
@@ -293,7 +311,8 @@ void test() {
   }
 
   {
-    using From = std::basic_string<CharT, constexpr_char_traits<CharT>, std::allocator<CharT>>;
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>,
+                                   std::allocator<CharT>>;
 
     test_string_view<Context>(From());
     test_string_view<Context>(From(empty.c_str()));
@@ -301,7 +320,8 @@ void test() {
   }
 
   {
-    using From = std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
+    using From =
+        std::basic_string<CharT, std::char_traits<CharT>, min_allocator<CharT>>;
 
     test_string_view<Context>(From());
     test_string_view<Context>(From(empty.c_str()));
@@ -309,7 +329,8 @@ void test() {
   }
 
   {
-    using From = std::basic_string<CharT, constexpr_char_traits<CharT>, min_allocator<CharT>>;
+    using From = std::basic_string<CharT, constexpr_char_traits<CharT>,
+                                   min_allocator<CharT>>;
 
     test_string_view<Context>(From());
     test_string_view<Context>(From(empty.c_str()));

>From 4eb32fddc048617547fec8242061f424eb4904f6 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sun, 31 Dec 2023 10:08:19 +0200
Subject: [PATCH 17/29] Restored formatting: get.pass.cpp

---
 .../format.arguments/format.args/get.pass.cpp | 80 ++++++++++++-------
 1 file changed, 51 insertions(+), 29 deletions(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
index 2b228c7e519a3a..3e82b07847b2cd 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
@@ -34,7 +34,6 @@ void test(From value) {
     else
       assert(false);
   };
-
 #if _LIBCPP_STD_VER >= 26
   format_args.get(0).visit(visitor);
 #endif
@@ -51,9 +50,8 @@ void test_handle(T value) {
   auto visitor = [](auto a) { assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>)); };
 #if _LIBCPP_STD_VER >= 26
   format_args.get(0).visit(visitor);
-#else
-  std::visit_format_arg(visitor, format_args.get(0));
 #endif
+  std::visit_format_arg(visitor, format_args.get(0));
 }
 
 // Test specific for string and string_view.
@@ -66,8 +64,8 @@ void test_string_view(From value) {
   const std::basic_format_args<Context> format_args{store};
 
   using CharT = typename Context::char_type;
-  using To    = std::basic_string_view<CharT>;
-  using V     = std::basic_string<CharT>;
+  using To = std::basic_string_view<CharT>;
+  using V = std::basic_string<CharT>;
 
   auto visitor = [v = V(value.begin(), value.end())](auto a) {
     if constexpr (std::is_same_v<To, decltype(a)>)
@@ -166,7 +164,8 @@ void test() {
   test<Context, int, int>(std::numeric_limits<short>::max());
   test<Context, int, int>(std::numeric_limits<int>::max());
 
-  using LongToType = std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
+  using LongToType =
+      std::conditional_t<sizeof(long) == sizeof(int), int, long long>;
 
   test<Context, LongToType, long>(std::numeric_limits<long>::min());
   test<Context, LongToType, long>(std::numeric_limits<int>::min());
@@ -197,11 +196,14 @@ void test() {
   // Test unsigned integer types.
 
   test<Context, unsigned, unsigned char>(0);
-  test<Context, unsigned, unsigned char>(std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned char>(
+      std::numeric_limits<unsigned char>::max());
 
   test<Context, unsigned, unsigned short>(0);
-  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned, unsigned short>(std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned, unsigned short>(
+      std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned, unsigned short>(
+      std::numeric_limits<unsigned short>::max());
 
   test<Context, unsigned, unsigned>(0);
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned char>::max());
@@ -209,20 +211,30 @@ void test() {
   test<Context, unsigned, unsigned>(std::numeric_limits<unsigned>::max());
 
   using UnsignedLongToType =
-      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned, unsigned long long>;
+      std::conditional_t<sizeof(unsigned long) == sizeof(unsigned), unsigned,
+                         unsigned long long>;
 
   test<Context, UnsignedLongToType, unsigned long>(0);
-  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned char>::max());
-  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned short>::max());
-  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned>::max());
-  test<Context, UnsignedLongToType, unsigned long>(std::numeric_limits<unsigned long>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned char>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned short>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned>::max());
+  test<Context, UnsignedLongToType, unsigned long>(
+      std::numeric_limits<unsigned long>::max());
 
   test<Context, unsigned long long, unsigned long long>(0);
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned char>::max());
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned short>::max());
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned>::max());
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long>::max());
-  test<Context, unsigned long long, unsigned long long>(std::numeric_limits<unsigned long long>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned char>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned short>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned long>::max());
+  test<Context, unsigned long long, unsigned long long>(
+      std::numeric_limits<unsigned long long>::max());
 
 #ifndef TEST_HAS_NO_INT128
   test_handle<Context, __uint128_t>(0);
@@ -244,12 +256,16 @@ void test() {
   test<Context, double, double>(std::numeric_limits<double>::min());
   test<Context, double, double>(std::numeric_limits<double>::max());
 
-  test<Context, long double, long double>(-std::numeric_limits<long double>::max());
-  test<Context, long double, long double>(-std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(
+      -std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(
+      -std::numeric_limits<long double>::min());
   test<Context, long double, long double>(-0.0);
   test<Context, long double, long double>(0.0);
-  test<Context, long double, long double>(std::numeric_limits<long double>::min());
-  test<Context, long double, long double>(std::numeric_limits<long double>::max());
+  test<Context, long double, long double>(
+      std::numeric_limits<long double>::min());
+  test<Context, long double, long double>(
+      std::numeric_limits<long double>::max());
 
   // Test const char_type pointer types.
 
@@ -258,15 +274,21 @@ void test() {
 
   // Test string_view types.
 
-  test<Context, std::basic_string_view<char_type>>(std::basic_string_view<char_type>());
-  test<Context, std::basic_string_view<char_type>, std::basic_string_view<char_type>>(empty);
-  test<Context, std::basic_string_view<char_type>, std::basic_string_view<char_type>>(str);
+  test<Context, std::basic_string_view<char_type>>(
+      std::basic_string_view<char_type>());
+  test<Context, std::basic_string_view<char_type>,
+       std::basic_string_view<char_type>>(empty);
+  test<Context, std::basic_string_view<char_type>,
+       std::basic_string_view<char_type>>(str);
 
   // Test string types.
 
-  test<Context, std::basic_string_view<char_type>>(std::basic_string<char_type>());
-  test<Context, std::basic_string_view<char_type>, std::basic_string<char_type>>(empty);
-  test<Context, std::basic_string_view<char_type>, std::basic_string<char_type>>(str);
+  test<Context, std::basic_string_view<char_type>>(
+      std::basic_string<char_type>());
+  test<Context, std::basic_string_view<char_type>,
+       std::basic_string<char_type>>(empty);
+  test<Context, std::basic_string_view<char_type>,
+       std::basic_string<char_type>>(str);
 
   // Test pointer types.
 

>From 87b46db7dd9172ada4e9d2e6e4d5f8566cb3d4f7 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Wed, 17 Jan 2024 22:35:13 +0200
Subject: [PATCH 18/29] Try to fix CI

---
 .../visit_format_arg.deprecated.verify.cpp    | 21 +++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
index 4b8c7ff3c9c4b4..dc9143fd6c2463 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
@@ -14,14 +14,23 @@
 //   see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
 
 #include <format>
+#include <tuple>
+
+#include "test_macros.h"
+
+template <typename CharT, class To, class From>
+void test(From value) {
+  using Context = std::basic_format_context<CharT*, CharT>;
+  auto store    = std::make_format_args<Context>(value);
+  std::basic_format_args<Context> format_args{store};
+
+  // expected-warning-re at +1 2 {{std::basic_format_context{{.*}}' is deprecated}}
+  std::ignore = std::visit_format_arg([]([[maybe_unused]] auto a) -> To { return {}; }, format_args.get(0));
+}
 
 void test() {
-  // expected-warning at +1 {{std::basic_format_context<char *, char>>' is deprecated}}
-  std::visit_format_arg([]([[maybe_unused]] auto a) -> char { return {}; },
-                        std::basic_format_arg<std::basic_format_context<char*, char>>{});
+  test<char, bool>('a');
 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
-  // expected-warning at +1 {{std::basic_format_context<wchar_t *, wchar_t>>' is deprecated}}
-  std::visit_format_arg([]([[maybe_unused]] auto a) -> wchar_t { return {}; },
-                        std::basic_format_arg<std::basic_format_context<wchar_t*, wchar_t>>{});
+  test<wchar_t, bool>('a');
 #endif
 }

>From b2200ef4c866e7bfae5c6fc7cb7e6aca20fefd38 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Wed, 17 Jan 2024 23:49:07 +0200
Subject: [PATCH 19/29] Try to fix CI

---
 .../format.arg/visit_format_arg.deprecated.verify.cpp           | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
index dc9143fd6c2463..af8baf4538d41e 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
@@ -24,7 +24,7 @@ void test(From value) {
   auto store    = std::make_format_args<Context>(value);
   std::basic_format_args<Context> format_args{store};
 
-  // expected-warning-re at +1 2 {{std::basic_format_context{{.*}}' is deprecated}}
+  // expected-warning-re at +1 1-2 {{std::basic_format_context{{.*}}' is deprecated}}
   std::ignore = std::visit_format_arg([]([[maybe_unused]] auto a) -> To { return {}; }, format_args.get(0));
 }
 

>From 3ea734643e878a8a3c11c0aa656c266c4ee87574 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Thu, 18 Jan 2024 20:28:17 +0200
Subject: [PATCH 20/29] Fix AIX and ARM CI

---
 libcxx/include/__format/format_arg.h                 | 12 ++++++++----
 libcxx/include/__format/format_context.h             |  2 +-
 .../format.arguments/format.arg/visit.pass.cpp       |  1 +
 .../format.arg/visit.return_type.pass.cpp            |  1 +
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index a7bcc3804f69e5..a3c8f535683c72 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -144,7 +144,8 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
   __libcpp_unreachable();
 }
 
-#  if _LIBCPP_STD_VER >= 26
+#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
+
 template <class _Rp, class _Visitor, class _Context>
 _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
   switch (__arg.__type_) {
@@ -193,7 +194,8 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
 
   __libcpp_unreachable();
 }
-#  endif
+
+#  endif // if _LIBCPP_STD_VER >= 26
 
 /// Contains the values used in basic_format_arg.
 ///
@@ -278,7 +280,8 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
 
   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
 
-#  if _LIBCPP_STD_VER >= 26
+#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
+
   // This function is user facing, so it must wrap the non-standard types of
   // the "variant" in a handle to stay conforming. See __arg_t for more details.
   template <class _Visitor>
@@ -320,7 +323,8 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
       return std::__visit_format_arg<_Rp>(std::forward<_Visitor>(__vis), __arg);
     }
   }
-#  endif
+
+#  endif // if _LIBCPP_STD_VER >= 26
 
 private:
   using char_type = typename _Context::char_type;
diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index d35268634bfe60..dcc32e64578855 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -175,7 +175,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
                   __format::__determine_arg_t<basic_format_context, decltype(__arg)>(),
                   __basic_format_arg_value<basic_format_context>(__arg)};
           };
-#  if _LIBCPP_STD_VER >= 26
+#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
           return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
 #  else
           return std::visit_format_arg(std::move(__visitor), static_cast<_Context*>(__c)->arg(__id));
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
index 84c5e059701420..2d5d20f47749a9 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
@@ -7,6 +7,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+// XFAIL: clang-16 || clang-17
 
 // <format>
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
index 986ecb174eb78f..e52cd98dd7fa96 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
@@ -7,6 +7,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+// XFAIL: clang-16 || clang-17
 
 // <format>
 

>From cfd5f6532011004c6c558423de038ea513a25e98 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Thu, 18 Jan 2024 21:01:53 +0200
Subject: [PATCH 21/29] Try to fix CI

---
 libcxx/include/__format/format_context.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index dcc32e64578855..9f6643fc791454 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -178,7 +178,10 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
 #  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
           return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
 #  else
+          _LIBCPP_DIAGNOSTIC_PUSH
+          _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
           return std::visit_format_arg(std::move(__visitor), static_cast<_Context*>(__c)->arg(__id));
+          _LIBCPP_DIAGNOSTIC_POP
 #  endif
         }) {
   }

>From fb1c24c538cc5a521eec2a91820ac4a1e1db1287 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Thu, 18 Jan 2024 22:51:23 +0200
Subject: [PATCH 22/29] Addressed comments

---
 libcxx/include/__format/format_arg.h              | 15 +++++++++------
 libcxx/include/__format/format_context.h          |  5 ++---
 .../format.arguments/format.arg/visit.pass.cpp    |  3 ++-
 .../format.arg/visit.return_type.pass.cpp         |  3 ++-
 .../visit_format_arg.deprecated.verify.cpp        |  1 +
 .../format.arguments/format.args/get.pass.cpp     |  9 +++------
 6 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index a3c8f535683c72..17182491fd49b2 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -144,7 +144,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
   __libcpp_unreachable();
 }
 
-#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
+#  if _LIBCPP_STD_VER >= 26 && defined(__cpp_explicit_this_parameter)
 
 template <class _Rp, class _Visitor, class _Context>
 _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
@@ -195,7 +195,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
   __libcpp_unreachable();
 }
 
-#  endif // if _LIBCPP_STD_VER >= 26
+#  endif // if _LIBCPP_STD_VER >= 26  && defined(__cpp_explicit_this_parameter)
 
 /// Contains the values used in basic_format_arg.
 ///
@@ -280,7 +280,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
 
   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
 
-#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
+#  if _LIBCPP_STD_VER >= 26 && defined(__cpp_explicit_this_parameter)
 
   // This function is user facing, so it must wrap the non-standard types of
   // the "variant" in a handle to stay conforming. See __arg_t for more details.
@@ -324,7 +324,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
     }
   }
 
-#  endif // if _LIBCPP_STD_VER >= 26
+#  endif // if _LIBCPP_STD_VER >= 26 && defined(__cpp_explicit_this_parameter)
 
 private:
   using char_type = typename _Context::char_type;
@@ -366,8 +366,11 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
 // This function is user facing, so it must wrap the non-standard types of
 // the "variant" in a handle to stay conforming. See __arg_t for more details.
 template <class _Visitor, class _Context>
-_LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_HIDE_FROM_ABI decltype(auto)
-visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
+#  ifdef __cpp_explicit_this_parameter
+_LIBCPP_DEPRECATED_IN_CXX26
+#  endif
+    _LIBCPP_HIDE_FROM_ABI decltype(auto)
+    visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
   switch (__arg.__type_) {
 #  ifndef _LIBCPP_HAS_NO_INT128
   case __format::__arg_t::__i128: {
diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index 9f6643fc791454..382819daadd97a 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -178,10 +178,9 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
 #  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
           return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
 #  else
-          _LIBCPP_DIAGNOSTIC_PUSH
-          _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
+          _LIBCPP_SUPPRESS_DEPRECATED_PUSH
           return std::visit_format_arg(std::move(__visitor), static_cast<_Context*>(__c)->arg(__id));
-          _LIBCPP_DIAGNOSTIC_POP
+          _LIBCPP_SUPPRESS_DEPRECATED_POP
 #  endif
         }) {
   }
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
index 2d5d20f47749a9..aa129c41893a0b 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
@@ -7,7 +7,8 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
-// XFAIL: clang-16 || clang-17
+// The tested functionality needs deducing this.
+// UNSUPPORTED: clang-16 || clang-17
 
 // <format>
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
index e52cd98dd7fa96..862ceaca1cdd6b 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
@@ -7,7 +7,8 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
-// XFAIL: clang-16 || clang-17
+// The tested functionality needs deducing this.
+// UNSUPPORTED: clang-16 || clang-17
 
 // <format>
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
index af8baf4538d41e..b2b2b6167300ef 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
@@ -7,6 +7,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+// UNSUPPORTED: clang-16 || clang-17
 
 // <format>
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
index 3e82b07847b2cd..f66b7bc7672d46 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
@@ -19,10 +19,6 @@
 #include "test_macros.h"
 #include "make_string.h"
 
-#if _LIBCPP_STD_VER >= 26
-TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
-#endif
-
 template <class Context, class To, class From>
 void test(From value) {
   auto store = std::make_format_args<Context>(value);
@@ -34,10 +30,11 @@ void test(From value) {
     else
       assert(false);
   };
-#if _LIBCPP_STD_VER >= 26
+#if _LIBCPP_STD_VER >= 26 && defined(__cpp_explicit_this_parameter)
   format_args.get(0).visit(visitor);
-#endif
+#else
   std::visit_format_arg(visitor, format_args.get(0));
+#endif
 }
 
 // Some types, as an extension, are stored in the variant. The Standard

>From ffc1020efafe3bebd0e077097f156bb4e9a9ebf4 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Thu, 18 Jan 2024 23:23:55 +0200
Subject: [PATCH 23/29] Revert Feature Test Macro (FTM) uses

---
 libcxx/include/__format/format_arg.h                 | 10 +++++-----
 .../format.arg/visit_format_arg.pass.cpp             |  2 +-
 .../format/format.arguments/format.args/get.pass.cpp | 12 +++++++-----
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index 17182491fd49b2..ff826254504311 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -144,7 +144,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
   __libcpp_unreachable();
 }
 
-#  if _LIBCPP_STD_VER >= 26 && defined(__cpp_explicit_this_parameter)
+#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
 
 template <class _Rp, class _Visitor, class _Context>
 _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
@@ -195,7 +195,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
   __libcpp_unreachable();
 }
 
-#  endif // if _LIBCPP_STD_VER >= 26  && defined(__cpp_explicit_this_parameter)
+#  endif // if _LIBCPP_STD_VER >= 26  && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
 
 /// Contains the values used in basic_format_arg.
 ///
@@ -280,7 +280,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
 
   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
 
-#  if _LIBCPP_STD_VER >= 26 && defined(__cpp_explicit_this_parameter)
+#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
 
   // This function is user facing, so it must wrap the non-standard types of
   // the "variant" in a handle to stay conforming. See __arg_t for more details.
@@ -324,7 +324,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
     }
   }
 
-#  endif // if _LIBCPP_STD_VER >= 26 && defined(__cpp_explicit_this_parameter)
+#  endif // if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
 
 private:
   using char_type = typename _Context::char_type;
@@ -366,7 +366,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
 // This function is user facing, so it must wrap the non-standard types of
 // the "variant" in a handle to stay conforming. See __arg_t for more details.
 template <class _Visitor, class _Context>
-#  ifdef __cpp_explicit_this_parameter
+#  if !defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800
 _LIBCPP_DEPRECATED_IN_CXX26
 #  endif
     _LIBCPP_HIDE_FROM_ABI decltype(auto)
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
index d4da9f92d9de73..cad028a28b6fc8 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
@@ -23,7 +23,7 @@
 #include "make_string.h"
 #include "min_allocator.h"
 
-#if _LIBCPP_STD_VER >= 26
+#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
 #endif
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
index f66b7bc7672d46..598a84ef7691ec 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
@@ -30,7 +30,7 @@ void test(From value) {
     else
       assert(false);
   };
-#if _LIBCPP_STD_VER >= 26 && defined(__cpp_explicit_this_parameter)
+#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
   format_args.get(0).visit(visitor);
 #else
   std::visit_format_arg(visitor, format_args.get(0));
@@ -45,10 +45,11 @@ void test_handle(T value) {
   std::basic_format_args<Context> format_args{store};
 
   auto visitor = [](auto a) { assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>)); };
-#if _LIBCPP_STD_VER >= 26
+#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
   format_args.get(0).visit(visitor);
-#endif
+#else
   std::visit_format_arg(visitor, format_args.get(0));
+#endif
 }
 
 // Test specific for string and string_view.
@@ -70,10 +71,11 @@ void test_string_view(From value) {
     else
       assert(false);
   };
-#if _LIBCPP_STD_VER >= 26
+#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
   format_args.get(0).visit(visitor);
-#endif
+#else
   std::visit_format_arg(visitor, format_args.get(0));
+#endif
 }
 
 template <class CharT>

>From 6f7535e715bdc06fba41a6af9c07350ddae71643 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hristo.goshev.hristov at gmail.com>
Date: Fri, 19 Jan 2024 01:33:36 +0200
Subject: [PATCH 24/29] Update libcxx/test/support/test_basic_format_arg.h

---
 libcxx/test/support/test_basic_format_arg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/support/test_basic_format_arg.h b/libcxx/test/support/test_basic_format_arg.h
index 91109e3a2d09f3..adee9f443b7eee 100644
--- a/libcxx/test/support/test_basic_format_arg.h
+++ b/libcxx/test/support/test_basic_format_arg.h
@@ -20,7 +20,7 @@ bool test_basic_format_arg(std::basic_format_arg<Context> arg, T expected) {
     else
       return false;
   };
-#if _LIBCPP_STD_VER >= 26
+#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
   return arg.visit(std::move(visitor));
 #else
   return std::visit_format_arg(std::move(visitor), arg);

>From dd7f629076acea72924c0a3e1328e92f0804a6e3 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sat, 20 Jan 2024 07:09:21 +0200
Subject: [PATCH 25/29] Added `TEST_HAS_EXPLICIT_THIS_PARAMETER` and
 `_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER`

---
 libcxx/include/__config                              |  5 +++++
 libcxx/include/__format/format_arg.h                 | 12 ++++++------
 libcxx/include/__format/format_context.h             |  2 +-
 .../format.arg/visit_format_arg.pass.cpp             |  2 +-
 .../format/format.arguments/format.args/get.pass.cpp |  6 +++---
 libcxx/test/support/test_basic_format_arg.h          |  2 +-
 libcxx/test/support/test_macros.h                    |  5 +++++
 7 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/libcxx/include/__config b/libcxx/include/__config
index 48f5528da330ad..558818ac90baf5 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1519,6 +1519,11 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
 #    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
 #  endif
 
+// Clang-18 has support for deducing this, but it does not set the FTM.
+#if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER ) &&_LIBCPP_CLANG_VER >= 1800)
+#  define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
+#endif
+
 #endif // __cplusplus
 
 #endif // _LIBCPP___CONFIG
diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index ff826254504311..1026438a29af61 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -144,7 +144,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
   __libcpp_unreachable();
 }
 
-#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
+#  if defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 
 template <class _Rp, class _Visitor, class _Context>
 _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
@@ -195,7 +195,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
   __libcpp_unreachable();
 }
 
-#  endif // if _LIBCPP_STD_VER >= 26  && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
+#  endif // if defined (_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 
 /// Contains the values used in basic_format_arg.
 ///
@@ -280,7 +280,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
 
   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
 
-#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
+#  if defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 
   // This function is user facing, so it must wrap the non-standard types of
   // the "variant" in a handle to stay conforming. See __arg_t for more details.
@@ -324,7 +324,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
     }
   }
 
-#  endif // if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
+#  endif // defined (_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 
 private:
   using char_type = typename _Context::char_type;
@@ -366,7 +366,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
 // This function is user facing, so it must wrap the non-standard types of
 // the "variant" in a handle to stay conforming. See __arg_t for more details.
 template <class _Visitor, class _Context>
-#  if !defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800
+#  if defined (_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 _LIBCPP_DEPRECATED_IN_CXX26
 #  endif
     _LIBCPP_HIDE_FROM_ABI decltype(auto)
@@ -382,7 +382,7 @@ _LIBCPP_DEPRECATED_IN_CXX26
     typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_};
     return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
   }
-#  endif
+#  endif // defined (_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
   default:
     return std::__visit_format_arg(std::forward<_Visitor>(__vis), __arg);
   }
diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index 382819daadd97a..ba6ebaf5904bb5 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -175,7 +175,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
                   __format::__determine_arg_t<basic_format_context, decltype(__arg)>(),
                   __basic_format_arg_value<basic_format_context>(__arg)};
           };
-#  if _LIBCPP_STD_VER >= 26 && (!defined(_LIBCPP_COMPILER_CLANG_BASED) || _LIBCPP_CLANG_VER >= 1800)
+#  if if defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
           return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
 #  else
           _LIBCPP_SUPPRESS_DEPRECATED_PUSH
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
index cad028a28b6fc8..17dc2ea4c7f245 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
@@ -23,7 +23,7 @@
 #include "make_string.h"
 #include "min_allocator.h"
 
-#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
+#if defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
 #endif
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
index 598a84ef7691ec..7b580e86095881 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
@@ -30,7 +30,7 @@ void test(From value) {
     else
       assert(false);
   };
-#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
+#if defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
   format_args.get(0).visit(visitor);
 #else
   std::visit_format_arg(visitor, format_args.get(0));
@@ -45,7 +45,7 @@ void test_handle(T value) {
   std::basic_format_args<Context> format_args{store};
 
   auto visitor = [](auto a) { assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>)); };
-#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
+#if defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
   format_args.get(0).visit(visitor);
 #else
   std::visit_format_arg(visitor, format_args.get(0));
@@ -71,7 +71,7 @@ void test_string_view(From value) {
     else
       assert(false);
   };
-#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
+#if defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
   format_args.get(0).visit(visitor);
 #else
   std::visit_format_arg(visitor, format_args.get(0));
diff --git a/libcxx/test/support/test_basic_format_arg.h b/libcxx/test/support/test_basic_format_arg.h
index adee9f443b7eee..4e56c253bcbb4e 100644
--- a/libcxx/test/support/test_basic_format_arg.h
+++ b/libcxx/test/support/test_basic_format_arg.h
@@ -20,7 +20,7 @@ bool test_basic_format_arg(std::basic_format_arg<Context> arg, T expected) {
     else
       return false;
   };
-#if _LIBCPP_STD_VER >= 26 && (!defined(TEST_COMPILER_CLANG) || TEST_CLANG_VER >= 1800)
+#if defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
   return arg.visit(std::move(visitor));
 #else
   return std::visit_format_arg(std::move(visitor), arg);
diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index fe68e13de6bcba..c2c22d180a4fd1 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -470,4 +470,9 @@ inline Tp const& DoNotOptimize(Tp const& value) {
 #  define TEST_IF_AIX(arg_true, arg_false) arg_false
 #endif
 
+// Clang-18 has support for deducing this, but it does not set the FTM.
+#if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER ) &&_LIBCPP_CLANG_VER >= 1800)
+#  define TEST_HAS_EXPLICIT_THIS_PARAMETER
+#endif
+
 #endif // SUPPORT_TEST_MACROS_HPP

>From 7eac0afc5474c624848d71ef86aeab57224fd7dc Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sat, 20 Jan 2024 07:11:07 +0200
Subject: [PATCH 26/29] Quick fix

---
 libcxx/include/__format/format_context.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index ba6ebaf5904bb5..3710c0d14b4013 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -175,7 +175,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
                   __format::__determine_arg_t<basic_format_context, decltype(__arg)>(),
                   __basic_format_arg_value<basic_format_context>(__arg)};
           };
-#  if if defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
+#  if defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
           return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
 #  else
           _LIBCPP_SUPPRESS_DEPRECATED_PUSH

>From ed2be273601ca10599519f51f6b991f8e90e16a6 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sat, 20 Jan 2024 07:23:10 +0200
Subject: [PATCH 27/29] Unsupport tests on *apple-clang*

---
 .../utilities/format/format.arguments/format.arg/visit.pass.cpp | 2 +-
 .../format.arguments/format.arg/visit.return_type.pass.cpp      | 2 +-
 .../format.arg/visit_format_arg.deprecated.verify.cpp           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
index aa129c41893a0b..618f5bfff636b7 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
@@ -8,7 +8,7 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 // The tested functionality needs deducing this.
-// UNSUPPORTED: clang-16 || clang-17
+// UNSUPPORTED: clang-16 || clang-17 || apple-clang
 
 // <format>
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
index 862ceaca1cdd6b..b4b17db918bda1 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
@@ -8,7 +8,7 @@
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
 // The tested functionality needs deducing this.
-// UNSUPPORTED: clang-16 || clang-17
+// UNSUPPORTED: clang-16 || clang-17 || apple-clang
 
 // <format>
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
index b2b2b6167300ef..435bc3084c2951 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp
@@ -7,7 +7,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
-// UNSUPPORTED: clang-16 || clang-17
+// UNSUPPORTED: clang-16 || clang-17 || apple-clang
 
 // <format>
 

>From 654afb9ee40a2a2aa97d3815ae0bc91cd3c48fe2 Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sat, 20 Jan 2024 07:50:04 +0200
Subject: [PATCH 28/29] Fixed formatting

---
 libcxx/test/support/test_macros.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index c2c22d180a4fd1..02202b8b8fed08 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -471,7 +471,7 @@ inline Tp const& DoNotOptimize(Tp const& value) {
 #endif
 
 // Clang-18 has support for deducing this, but it does not set the FTM.
-#if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER ) &&_LIBCPP_CLANG_VER >= 1800)
+#if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
 #  define TEST_HAS_EXPLICIT_THIS_PARAMETER
 #endif
 

>From e73184cfd3675d112d61e78e4772c70d7532b5fa Mon Sep 17 00:00:00 2001
From: Zingam <zingam at outlook.com>
Date: Sat, 20 Jan 2024 08:30:06 +0200
Subject: [PATCH 29/29] Fixed mistake

---
 libcxx/include/__format/format_arg.h                 | 12 ++++++------
 libcxx/include/__format/format_context.h             |  4 ++--
 .../format.arg/visit_format_arg.pass.cpp             |  2 +-
 .../format/format.arguments/format.args/get.pass.cpp |  4 ++--
 libcxx/test/support/test_basic_format_arg.h          |  2 +-
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libcxx/include/__format/format_arg.h b/libcxx/include/__format/format_arg.h
index 1026438a29af61..02ee3cef7d402b 100644
--- a/libcxx/include/__format/format_arg.h
+++ b/libcxx/include/__format/format_arg.h
@@ -144,7 +144,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_
   __libcpp_unreachable();
 }
 
-#  if defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
+#  if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 
 template <class _Rp, class _Visitor, class _Context>
 _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) {
@@ -195,7 +195,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
   __libcpp_unreachable();
 }
 
-#  endif // if defined (_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
+#  endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 
 /// Contains the values used in basic_format_arg.
 ///
@@ -280,7 +280,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
 
   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; }
 
-#  if defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
+#  if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 
   // This function is user facing, so it must wrap the non-standard types of
   // the "variant" in a handle to stay conforming. See __arg_t for more details.
@@ -324,7 +324,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg {
     }
   }
 
-#  endif // defined (_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
+#  endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 
 private:
   using char_type = typename _Context::char_type;
@@ -366,7 +366,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle {
 // This function is user facing, so it must wrap the non-standard types of
 // the "variant" in a handle to stay conforming. See __arg_t for more details.
 template <class _Visitor, class _Context>
-#  if defined (_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
+#  if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
 _LIBCPP_DEPRECATED_IN_CXX26
 #  endif
     _LIBCPP_HIDE_FROM_ABI decltype(auto)
@@ -382,7 +382,7 @@ _LIBCPP_DEPRECATED_IN_CXX26
     typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_};
     return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h});
   }
-#  endif // defined (_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
+#  endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
   default:
     return std::__visit_format_arg(std::forward<_Visitor>(__vis), __arg);
   }
diff --git a/libcxx/include/__format/format_context.h b/libcxx/include/__format/format_context.h
index 3710c0d14b4013..0beaa84b028beb 100644
--- a/libcxx/include/__format/format_context.h
+++ b/libcxx/include/__format/format_context.h
@@ -175,13 +175,13 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context<typename __format::__retarget_bu
                   __format::__determine_arg_t<basic_format_context, decltype(__arg)>(),
                   __basic_format_arg_value<basic_format_context>(__arg)};
           };
-#  if defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
+#  if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
           return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor));
 #  else
           _LIBCPP_SUPPRESS_DEPRECATED_PUSH
           return std::visit_format_arg(std::move(__visitor), static_cast<_Context*>(__c)->arg(__id));
           _LIBCPP_SUPPRESS_DEPRECATED_POP
-#  endif
+#  endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER)
         }) {
   }
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
index 17dc2ea4c7f245..6a61f66b989cd6 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.pass.cpp
@@ -23,7 +23,7 @@
 #include "make_string.h"
 #include "min_allocator.h"
 
-#if defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
+#if _LIBCPP_STD_VER >= 26 && defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
 #endif
 
diff --git a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
index 7b580e86095881..a3f249a524a823 100644
--- a/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
+++ b/libcxx/test/std/utilities/format/format.arguments/format.args/get.pass.cpp
@@ -30,7 +30,7 @@ void test(From value) {
     else
       assert(false);
   };
-#if defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
+#if _LIBCPP_STD_VER >= 26 && defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
   format_args.get(0).visit(visitor);
 #else
   std::visit_format_arg(visitor, format_args.get(0));
@@ -45,7 +45,7 @@ void test_handle(T value) {
   std::basic_format_args<Context> format_args{store};
 
   auto visitor = [](auto a) { assert((std::is_same_v<decltype(a), typename std::basic_format_arg<Context>::handle>)); };
-#if defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
+#if _LIBCPP_STD_VER >= 26 && defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
   format_args.get(0).visit(visitor);
 #else
   std::visit_format_arg(visitor, format_args.get(0));
diff --git a/libcxx/test/support/test_basic_format_arg.h b/libcxx/test/support/test_basic_format_arg.h
index 4e56c253bcbb4e..95ca3b48c756d1 100644
--- a/libcxx/test/support/test_basic_format_arg.h
+++ b/libcxx/test/support/test_basic_format_arg.h
@@ -20,7 +20,7 @@ bool test_basic_format_arg(std::basic_format_arg<Context> arg, T expected) {
     else
       return false;
   };
-#if defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
+#if _LIBCPP_STD_VER >= 26 && defined(TEST_HAS_EXPLICIT_THIS_PARAMETER)
   return arg.visit(std::move(visitor));
 #else
   return std::visit_format_arg(std::move(visitor), arg);



More information about the flang-commits mailing list