[libcxx-commits] [libcxx] c40a686 - [libc++] Strip cv-refs in __desugars_to specialization for integral types (#208950)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 21 04:40:27 PDT 2026
Author: Michael G. Kazakov
Date: 2026-07-21T07:40:22-04:00
New Revision: c40a68644c550dcfa3c3d0b560e3aeea1d159d79
URL: https://github.com/llvm/llvm-project/commit/c40a68644c550dcfa3c3d0b560e3aeea1d159d79
DIFF: https://github.com/llvm/llvm-project/commit/c40a68644c550dcfa3c3d0b560e3aeea1d159d79.diff
LOG: [libc++] Strip cv-refs in __desugars_to specialization for integral types (#208950)
This PR passes the argument type through `__remove_cvref_t` before
passing to `is_integral`.
Fixes #208236
Added:
Modified:
libcxx/include/__algorithm/comp.h
libcxx/test/libcxx/type_traits/desugars_to.compile.pass.cpp
Removed:
################################################################################
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/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