authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-14 12:10:41+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-14 12:10:41+02:00
logbc58b5dc53cce066d224925ce8fb4bb79665a1d1
treec3d233ed01cd67660f13a7b37a8166875468e4da
parent10ea69912f8b4f86e18198bf597a8777e02ac0ca
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

libcxx: backport llvm/llvm-project#155786

https://github.com/llvm/llvm-project/pull/155786

2 files changed, 35 insertions(+), 4 deletions(-)

lib/libcxx/include/__functional/hash.h+10-4
......@@ -21,6 +21,7 @@
2121#include <__type_traits/is_enum.h>
2222#include <__type_traits/is_floating_point.h>
2323#include <__type_traits/is_integral.h>
24#include <__type_traits/is_unqualified.h>
2425#include <__type_traits/underlying_type.h>
2526#include <__utility/pair.h>
2627#include <__utility/swap.h>
......@@ -355,7 +356,8 @@ struct __hash_impl {
355356};
356357
357358template <class _Tp>
358struct __hash_impl<_Tp, __enable_if_t<is_enum<_Tp>::value> > : __unary_function<_Tp, size_t> {
359struct __hash_impl<_Tp, __enable_if_t<is_enum<_Tp>::value && __is_unqualified_v<_Tp> > >
360 : __unary_function<_Tp, size_t> {
359361 _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT {
360362 using type = __underlying_type_t<_Tp>;
361363 return hash<type>()(static_cast<type>(__v));
......@@ -363,17 +365,21 @@ struct __hash_impl<_Tp, __enable_if_t<is_enum<_Tp>::value> > : __unary_function<
363365};
364366
365367template <class _Tp>
366struct __hash_impl<_Tp, __enable_if_t<is_integral<_Tp>::value && (sizeof(_Tp) <= sizeof(size_t))> >
368struct __hash_impl<
369 _Tp,
370 __enable_if_t<is_integral<_Tp>::value && __is_unqualified_v<_Tp> && (sizeof(_Tp) <= sizeof(size_t))> >
367371 : __unary_function<_Tp, size_t> {
368372 _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT { return static_cast<size_t>(__v); }
369373};
370374
371375template <class _Tp>
372struct __hash_impl<_Tp, __enable_if_t<is_integral<_Tp>::value && (sizeof(_Tp) > sizeof(size_t))> >
376struct __hash_impl<_Tp,
377 __enable_if_t<is_integral<_Tp>::value && __is_unqualified_v<_Tp> && (sizeof(_Tp) > sizeof(size_t))> >
373378 : __scalar_hash<_Tp> {};
374379
375380template <class _Tp>
376struct __hash_impl<_Tp, __enable_if_t<is_floating_point<_Tp>::value> > : __scalar_hash<_Tp> {
381struct __hash_impl<_Tp, __enable_if_t<is_floating_point<_Tp>::value && __is_unqualified_v<_Tp> > >
382 : __scalar_hash<_Tp> {
377383 _LIBCPP_HIDE_FROM_ABI size_t operator()(_Tp __v) const _NOEXCEPT {
378384 // -0.0 and 0.0 should return same hash
379385 if (__v == 0.0f)
lib/libcxx/include/__type_traits/is_unqualified.h created+25
......@@ -0,0 +1,25 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___TYPE_TRAITS_IS_UNQUALIFIED_H
10#define _LIBCPP___TYPE_TRAITS_IS_UNQUALIFIED_H
11
12#include <__config>
13
14#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15# pragma GCC system_header
16#endif
17
18_LIBCPP_BEGIN_NAMESPACE_STD
19
20template <class _Tp>
21inline const bool __is_unqualified_v = __is_same(_Tp, __remove_cvref(_Tp));
22
23_LIBCPP_END_NAMESPACE_STD
24
25#endif // _LIBCPP___TYPE_TRAITS_IS_UNQUALIFIED_H