Skip to content

Commit bc58b5d

Browse files
committed
1 parent 10ea699 commit bc58b5d

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

lib/libcxx/include/__functional/hash.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,25 +356,30 @@ struct __hash_impl {
355356
};
356357

357358
template <class _Tp>
358-
struct __hash_impl<_Tp, __enable_if_t<is_enum<_Tp>::value> > : __unary_function<_Tp, size_t> {
359+
struct __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));
362364
}
363365
};
364366

365367
template <class _Tp>
366-
struct __hash_impl<_Tp, __enable_if_t<is_integral<_Tp>::value && (sizeof(_Tp) <= sizeof(size_t))> >
368+
struct __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

371375
template <class _Tp>
372-
struct __hash_impl<_Tp, __enable_if_t<is_integral<_Tp>::value && (sizeof(_Tp) > sizeof(size_t))> >
376+
struct __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

375380
template <class _Tp>
376-
struct __hash_impl<_Tp, __enable_if_t<is_floating_point<_Tp>::value> > : __scalar_hash<_Tp> {
381+
struct __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)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
20+
template <class _Tp>
21+
inline 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

0 commit comments

Comments
 (0)