Skip to content

Commit 3bb903e

Browse files
[libc++] Treat P0513R0 as a defect report against C++11 (#166690)
P0513R0 is essentially a collective resolution paper of LWG2543, LWG2791, LWG2809, and LWG2817. Among these LWG issues, LWG2543 (conditionally enabled `hash`) and LWG2817 (`hash<nullptr_t>`) affect pre-C++17 utilities. We generally backport changes from LWG issues, so this patch backports the relevant parts of P0513R0. Although we provide `hash<unique_ptr>` as an extension in C++03 mode, as C++03 mode isn't encouraged now, this patch leaves `hash<unique_ptr>` unchanged in C++03 mode.
1 parent 91821ba commit 3bb903e

File tree

5 files changed

+12
-29
lines changed

5 files changed

+12
-29
lines changed

libcxx/docs/Status/Cxx17Papers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"`P0508R0 <https://wg21.link/P0508R0>`__","Wording for GB 58 - structured bindings for node_handles","2016-11 (Issaquah)","|Complete|","7","`#99944 <https://github.com/llvm/llvm-project/issues/99944>`__",""
8585
"`P0509R1 <https://wg21.link/P0509R1>`__","Updating ""Restrictions on exception handling""","2016-11 (Issaquah)","|Nothing To Do|","n/a","`#103676 <https://github.com/llvm/llvm-project/issues/103676>`__",""
8686
"`P0510R0 <https://wg21.link/P0510R0>`__","Disallowing references, incomplete types, arrays, and empty variants","2016-11 (Issaquah)","|Complete|","4","`#103677 <https://github.com/llvm/llvm-project/issues/103677>`__",""
87-
"`P0513R0 <https://wg21.link/P0513R0>`__","Poisoning the Hash","2016-11 (Issaquah)","|Complete|","5","`#103678 <https://github.com/llvm/llvm-project/issues/103678>`__",""
87+
"`P0513R0 <https://wg21.link/P0513R0>`__","Poisoning the Hash","2016-11 (Issaquah)","|Complete|","5","`#103678 <https://github.com/llvm/llvm-project/issues/103678>`__","Implemented as a DR against C++11 since LLVM 22. MSVC STL does the same."
8888
"`P0516R0 <https://wg21.link/P0516R0>`__","Clarify That shared_future's Copy Operations have Wide Contracts","2016-11 (Issaquah)","|Complete|","4","`#103679 <https://github.com/llvm/llvm-project/issues/103679>`__",""
8989
"`P0517R0 <https://wg21.link/P0517R0>`__","Make future_error Constructible","2016-11 (Issaquah)","|Complete|","4","`#103680 <https://github.com/llvm/llvm-project/issues/103680>`__",""
9090
"`P0521R0 <https://wg21.link/P0521R0>`__","Proposed Resolution for CA 14 (shared_ptr use_count/unique)","2016-11 (Issaquah)","|Complete|","18","`#103681 <https://github.com/llvm/llvm-project/issues/103681>`__",""

libcxx/include/__functional/hash.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,10 @@ struct __hash_impl<long double> : __scalar_hash<long double> {
433433
template <class _Tp>
434434
struct hash : public __hash_impl<_Tp> {};
435435

436-
#if _LIBCPP_STD_VER >= 17
437-
438436
template <>
439437
struct hash<nullptr_t> : public __unary_function<nullptr_t, size_t> {
440438
_LIBCPP_HIDE_FROM_ABI size_t operator()(nullptr_t) const _NOEXCEPT { return 662607004ull; }
441439
};
442-
#endif
443440

444441
#ifndef _LIBCPP_CXX03_LANG
445442
template <class _Key, class _Hash>
@@ -452,18 +449,12 @@ template <class _Key, class _Hash = hash<_Key> >
452449
using __has_enabled_hash _LIBCPP_NODEBUG =
453450
integral_constant<bool, __check_hash_requirements<_Key, _Hash>::value && is_default_constructible<_Hash>::value >;
454451

455-
# if _LIBCPP_STD_VER >= 17
456452
template <class _Type, class>
457453
using __enable_hash_helper_imp _LIBCPP_NODEBUG = _Type;
458454

459455
template <class _Type, class... _Keys>
460456
using __enable_hash_helper _LIBCPP_NODEBUG =
461457
__enable_hash_helper_imp<_Type, __enable_if_t<__all<__has_enabled_hash<_Keys>::value...>::value> >;
462-
# else
463-
template <class _Type, class...>
464-
using __enable_hash_helper _LIBCPP_NODEBUG = _Type;
465-
# endif
466-
467458
#endif // !_LIBCPP_CXX03_LANG
468459

469460
_LIBCPP_END_NAMESPACE_STD

libcxx/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// size_t operator()(T val) const;
1818
// };
1919

20+
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
21+
2022
// Not very portable
2123

2224
#include <cassert>
@@ -44,18 +46,14 @@ test()
4446
assert(h(&i) != h(&j));
4547
}
4648

47-
// can't hash nullptr_t until C++17
48-
void test_nullptr()
49-
{
50-
#if TEST_STD_VER > 14
51-
typedef std::nullptr_t T;
52-
typedef std::hash<T> H;
49+
void test_nullptr() {
50+
typedef std::nullptr_t T;
51+
typedef std::hash<T> H;
5352
#if TEST_STD_VER <= 17
54-
static_assert((std::is_same<typename H::argument_type, T>::value), "" );
55-
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
56-
#endif
57-
ASSERT_NOEXCEPT(H()(T()));
53+
static_assert((std::is_same<typename H::argument_type, T>::value), "");
54+
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "");
5855
#endif
56+
ASSERT_NOEXCEPT(H()(T()));
5957
}
6058

6159
int main(int, char**)

libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ int main(int, char**)
9090
test_enabled_with_deleter<A, PointerDeleter<A, 1>>();
9191
test_enabled_with_deleter<A[], PointerDeleter<A[], 1>>();
9292

93-
#if TEST_STD_VER > 14
9493
test_disabled_with_deleter<int, PointerDeleter<int, 0>>();
9594
test_disabled_with_deleter<int[], PointerDeleter<int[], 0>>();
9695
test_disabled_with_deleter<A, PointerDeleter<A, 0>>();
9796
test_disabled_with_deleter<A[], PointerDeleter<A[], 0>>();
98-
#endif
9997
}
10098
#endif
10199

libcxx/test/support/poisoned_hash_helper.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,9 @@ struct Class {};
123123
// Each header that declares the std::hash template provides enabled
124124
// specializations of std::hash for std::nullptr_t and all cv-unqualified
125125
// arithmetic, enumeration, and pointer types.
126-
#if TEST_STD_VER >= 17
127-
using MaybeNullptr = types::type_list<std::nullptr_t>;
128-
#else
129-
using MaybeNullptr = types::type_list<>;
130-
#endif
131-
using LibraryHashTypes = types::
132-
concatenate_t<types::arithmetic_types, types::type_list<Enum, EnumClass, void*, void const*, Class*>, MaybeNullptr>;
126+
using LibraryHashTypes =
127+
types::concatenate_t<types::arithmetic_types,
128+
types::type_list<Enum, EnumClass, void*, void const*, Class*, std::nullptr_t>>;
133129

134130
struct TestHashEnabled {
135131
template <class T>

0 commit comments

Comments
 (0)