[libcxx-commits] [libcxx] [libc++] __desugars_to_v<__totally_ordered_less_tag, __less<>, _Tp, _Tp> removes cv-ref from _Tp (PR #208950)

Michael G. Kazakov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jul 19 04:36:05 PDT 2026


https://github.com/mikekazakov updated https://github.com/llvm/llvm-project/pull/208950

>From de4502a3bac34eedba2d5687e67bb6be577e51e7 Mon Sep 17 00:00:00 2001
From: Michael Kazakov <mike.kazakov at gmail.com>
Date: Sat, 11 Jul 2026 21:19:44 +0100
Subject: [PATCH 1/4] __desugars_to_v<__totally_ordered_less_tag, __less<>,...>
 strips cv-ref from _Tp

---
 libcxx/include/__algorithm/comp.h           |  4 ++-
 libcxx/test/libcxx/algorithms/comp.pass.cpp | 27 +++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/test/libcxx/algorithms/comp.pass.cpp

diff --git a/libcxx/include/__algorithm/comp.h b/libcxx/include/__algorithm/comp.h
index 38e2fb9f5e744..a83b6a8938998 100644
--- a/libcxx/include/__algorithm/comp.h
+++ b/libcxx/include/__algorithm/comp.h
@@ -13,6 +13,7 @@
 #include <__type_traits/desugars_to.h>
 #include <__type_traits/is_generic_transparent_comparator.h>
 #include <__type_traits/is_integral.h>
+#include <__type_traits/remove_cvref.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -47,7 +48,8 @@ template <class _Tp>
 inline const bool __desugars_to_v<__less_tag, __less<>, _Tp, _Tp> = true;
 
 template <class _Tp>
-inline const bool __desugars_to_v<__totally_ordered_less_tag, __less<>, _Tp, _Tp> = is_integral<_Tp>::value;
+inline const bool __desugars_to_v<__totally_ordered_less_tag, __less<>, _Tp, _Tp> =
+    is_integral<__remove_cvref_t<_Tp> >::value;
 
 template <>
 inline const bool __is_generic_transparent_comparator_v<__less<> > = true;
diff --git a/libcxx/test/libcxx/algorithms/comp.pass.cpp b/libcxx/test/libcxx/algorithms/comp.pass.cpp
new file mode 100644
index 0000000000000..87095f630ee52
--- /dev/null
+++ b/libcxx/test/libcxx/algorithms/comp.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++17
+
+// <__algorithm/comp.h>
+
+#include <__algorithm/comp.h>
+
+// check that __less<> desugars to __totally_ordered_less_tag for integral types regardless of their cv-ref
+static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, int, int>);
+static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, int&, int&>);
+static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, const int, const int>);
+static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, const int&, const int&>);
+static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, volatile int&, volatile int&>);
+static_assert(
+    std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, volatile const int&, volatile const int&>);
+static_assert(
+    !std::
+        __desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, volatile const float&, volatile const float&>);
+
+int main(int, char**) { return 0; }

>From dca57eead03572af638250c92ceddb9a055f9df8 Mon Sep 17 00:00:00 2001
From: Michael Kazakov <mike.kazakov at gmail.com>
Date: Sun, 12 Jul 2026 13:47:14 +0100
Subject: [PATCH 2/4] Include <algorithm> instead of an individual header

---
 libcxx/test/libcxx/algorithms/comp.pass.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/test/libcxx/algorithms/comp.pass.cpp b/libcxx/test/libcxx/algorithms/comp.pass.cpp
index 87095f630ee52..0e3b813aedca3 100644
--- a/libcxx/test/libcxx/algorithms/comp.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/comp.pass.cpp
@@ -8,9 +8,9 @@
 
 // REQUIRES: std-at-least-c++17
 
-// <__algorithm/comp.h>
+// <algorithm>
 
-#include <__algorithm/comp.h>
+#include <algorithm>
 
 // check that __less<> desugars to __totally_ordered_less_tag for integral types regardless of their cv-ref
 static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, int, int>);

>From 606e8708b053547c7b088af600dde89f9d469557 Mon Sep 17 00:00:00 2001
From: Michael Kazakov <mike.kazakov at gmail.com>
Date: Tue, 14 Jul 2026 21:14:41 +0100
Subject: [PATCH 3/4] Include <__type_traits/desugars_to.h> as well

---
 libcxx/test/libcxx/algorithms/comp.pass.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libcxx/test/libcxx/algorithms/comp.pass.cpp b/libcxx/test/libcxx/algorithms/comp.pass.cpp
index 0e3b813aedca3..deff69eb765f7 100644
--- a/libcxx/test/libcxx/algorithms/comp.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/comp.pass.cpp
@@ -10,6 +10,8 @@
 
 // <algorithm>
 
+#include <__type_traits/desugars_to.h>
+
 #include <algorithm>
 
 // check that __less<> desugars to __totally_ordered_less_tag for integral types regardless of their cv-ref

>From 7e5c4b49d062ab704f15bfd554df8a60e3ff9809 Mon Sep 17 00:00:00 2001
From: Michael Kazakov <mike.kazakov at gmail.com>
Date: Wed, 15 Jul 2026 21:07:36 +0100
Subject: [PATCH 4/4] Moved the test to desugars_to.compile.pass.cpp

---
 libcxx/test/libcxx/algorithms/comp.pass.cpp   | 29 -------------------
 .../type_traits/desugars_to.compile.pass.cpp  | 19 ++++++++++++
 2 files changed, 19 insertions(+), 29 deletions(-)
 delete mode 100644 libcxx/test/libcxx/algorithms/comp.pass.cpp

diff --git a/libcxx/test/libcxx/algorithms/comp.pass.cpp b/libcxx/test/libcxx/algorithms/comp.pass.cpp
deleted file mode 100644
index deff69eb765f7..0000000000000
--- a/libcxx/test/libcxx/algorithms/comp.pass.cpp
+++ /dev/null
@@ -1,29 +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
-//
-//===----------------------------------------------------------------------===//
-
-// REQUIRES: std-at-least-c++17
-
-// <algorithm>
-
-#include <__type_traits/desugars_to.h>
-
-#include <algorithm>
-
-// check that __less<> desugars to __totally_ordered_less_tag for integral types regardless of their cv-ref
-static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, int, int>);
-static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, int&, int&>);
-static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, const int, const int>);
-static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, const int&, const int&>);
-static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, volatile int&, volatile int&>);
-static_assert(
-    std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, volatile const int&, volatile const int&>);
-static_assert(
-    !std::
-        __desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, volatile const float&, volatile const float&>);
-
-int main(int, char**) { return 0; }
diff --git a/libcxx/test/libcxx/type_traits/desugars_to.compile.pass.cpp b/libcxx/test/libcxx/type_traits/desugars_to.compile.pass.cpp
index 9134ac027d1ed..e28dbd8fa9ff2 100644
--- a/libcxx/test/libcxx/type_traits/desugars_to.compile.pass.cpp
+++ b/libcxx/test/libcxx/type_traits/desugars_to.compile.pass.cpp
@@ -10,6 +10,7 @@
 // UNSUPPORTED: gcc && c++11
 
 #include <__type_traits/desugars_to.h>
+#include <__algorithm/comp.h>
 
 struct Tag {};
 struct Operation {};
@@ -37,4 +38,22 @@ void tests() {
     static_assert(std::__desugars_to_v<Tag, Operation&&>, "");
     static_assert(std::__desugars_to_v<Tag, Operation const&&>, "");
   }
+
+  // Make sure that __less<> desugars to __totally_ordered_less_tag for integral types regardless of their cv-ref
+  {
+    static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, int, int>, "");
+    static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, int&, int&>, "");
+    static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, const int, const int>, "");
+    static_assert(std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, const int&, const int&>, "");
+    static_assert(
+        std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, volatile int&, volatile int&>, "");
+    static_assert(
+        std::__desugars_to_v<std::__totally_ordered_less_tag, std::__less<>, volatile const int&, volatile const int&>,
+        "");
+    static_assert(!std::__desugars_to_v<std::__totally_ordered_less_tag,
+                                        std::__less<>,
+                                        volatile const float&,
+                                        volatile const float&>,
+                  "");
+  }
 }



More information about the libcxx-commits mailing list