[libcxx-commits] [libcxx] __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
Sat Jul 11 13:22:56 PDT 2026
https://github.com/mikekazakov created https://github.com/llvm/llvm-project/pull/208950
This PR passes the argument type through `__remove_cvref_t` before passing to `is_integral`.
Fixes #208236
>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] __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; }
More information about the libcxx-commits
mailing list