Skip to content

Commit 3332552

Browse files
authored
[libc++][modules] Refactor poisoned_hash_helper (#108296)
The poisoned_hash_helper header was relying on an implicit forward declaration of std::hash located in <type_traits>. When we improve the modularization of the library, that causes issues, in addition to being a fundamentally non-portable assumption in the test suite. It turns out that the reason for relying on a forward declaration is to be able to test that std::hash is *not* provided if we don't include any header that provides it. But testing that is actually both non-portable and not really useful. Indeed, what harm does it make if additional headers provide std::hash specializations? That would certainly be conforming -- the Standard never requires an implementation to avoid providing a declaration when a given header is included, instead it mandates what *must* be provided for sure. In that spirit, it would be conforming for e.g. `<cstddef>` to define the hash specializations if that was our desire. I also don't read https://wg21.link/P0513R0 as going against that statement. Hence, this patch just removes that test which doesn't carry its weight. Fixes #56938
1 parent 030c6da commit 3332552

File tree

16 files changed

+92
-223
lines changed

16 files changed

+92
-223
lines changed

libcxx/include/type_traits

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ namespace std
421421
*/
422422

423423
#include <__config>
424-
#include <__fwd/functional.h> // This is https://llvm.org/PR56938
425424
#include <__type_traits/add_const.h>
426425
#include <__type_traits/add_cv.h>
427426
#include <__type_traits/add_lvalue_reference.h>

libcxx/test/std/containers/sequences/vector.bool/enabled_hash.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "min_allocator.h"
2121

2222
TEST_CONSTEXPR_CXX20 bool test() {
23-
test_hash_enabled_for_type<std::vector<bool> >();
24-
test_hash_enabled_for_type<std::vector<bool, min_allocator<bool>>>();
23+
test_hash_enabled<std::vector<bool> >();
24+
test_hash_enabled<std::vector<bool, min_allocator<bool>>>();
2525

2626
return true;
2727
}

libcxx/test/std/diagnostics/syserr/syserr.hash/enabled_hash.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
int main(int, char**) {
2323
test_library_hash_specializations_available();
2424
{
25-
test_hash_enabled_for_type<std::error_code>();
26-
test_hash_enabled_for_type<std::error_condition>();
25+
test_hash_enabled<std::error_code>();
26+
test_hash_enabled<std::error_condition>();
2727
}
2828

2929
return 0;

libcxx/test/std/experimental/memory/memory.observer.ptr/hash.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void test_hash() {
3333
assert(h == std::hash<T*>()(&obj));
3434
}
3535

36-
test_hash_enabled_for_type<std::experimental::observer_ptr<T>>();
36+
test_hash_enabled<std::experimental::observer_ptr<T>>();
3737
}
3838

3939
struct Bar {};

libcxx/test/std/input.output/filesystems/class.path/path.member/path.hash_enabled.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace fs = std::filesystem;
2020

2121
int main(int, char**) {
2222
test_library_hash_specializations_available();
23-
test_hash_enabled_for_type<fs::path>();
23+
test_hash_enabled<fs::path>();
2424

2525
return 0;
2626
}

libcxx/test/std/strings/basic.string.hash/enabled_hashes.pass.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ struct std::char_traits<MyChar> {
5353
int main(int, char**) {
5454
test_library_hash_specializations_available();
5555
{
56-
test_hash_enabled_for_type<std::string>();
56+
test_hash_enabled<std::string>();
5757
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
58-
test_hash_enabled_for_type<std::wstring>();
58+
test_hash_enabled<std::wstring>();
5959
#endif
6060
#ifndef TEST_HAS_NO_CHAR8_T
61-
test_hash_enabled_for_type<std::u8string>();
61+
test_hash_enabled<std::u8string>();
6262
#endif
63-
test_hash_enabled_for_type<std::u16string>();
64-
test_hash_enabled_for_type<std::u32string>();
65-
test_hash_enabled_for_type<std::basic_string<char, std::char_traits<char>, test_allocator<char>>>();
66-
test_hash_disabled_for_type<std::basic_string<MyChar, std::char_traits<MyChar>, std::allocator<MyChar>>>();
67-
test_hash_disabled_for_type<std::basic_string<char, constexpr_char_traits<char>, std::allocator<char>>>();
63+
test_hash_enabled<std::u16string>();
64+
test_hash_enabled<std::u32string>();
65+
test_hash_enabled<std::basic_string<char, std::char_traits<char>, test_allocator<char>>>();
66+
test_hash_disabled<std::basic_string<MyChar, std::char_traits<MyChar>, std::allocator<MyChar>>>();
67+
test_hash_disabled<std::basic_string<char, constexpr_char_traits<char>, std::allocator<char>>>();
6868
}
6969

7070
return 0;

libcxx/test/std/strings/string.view/string.view.hash/enabled_hashes.pass.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ struct std::char_traits<MyChar> {
5353
int main(int, char**) {
5454
test_library_hash_specializations_available();
5555
{
56-
test_hash_enabled_for_type<std::string_view>();
56+
test_hash_enabled<std::string_view>();
5757
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
58-
test_hash_enabled_for_type<std::wstring_view>();
58+
test_hash_enabled<std::wstring_view>();
5959
#endif
6060
#ifndef TEST_HAS_NO_CHAR8_T
61-
test_hash_enabled_for_type<std::u8string_view>();
61+
test_hash_enabled<std::u8string_view>();
6262
#endif
63-
test_hash_enabled_for_type<std::u16string_view>();
64-
test_hash_enabled_for_type<std::u32string_view>();
65-
test_hash_disabled_for_type<std::basic_string_view<MyChar, std::char_traits<MyChar>>>();
66-
test_hash_disabled_for_type<std::basic_string_view<char, constexpr_char_traits<char>>>();
63+
test_hash_enabled<std::u16string_view>();
64+
test_hash_enabled<std::u32string_view>();
65+
test_hash_disabled<std::basic_string_view<MyChar, std::char_traits<MyChar>>>();
66+
test_hash_disabled<std::basic_string_view<char, constexpr_char_traits<char>>>();
6767
}
6868

6969
return 0;

libcxx/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/enabled_hashes.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
int main(int, char**) {
2525
test_library_hash_specializations_available();
2626
{
27-
test_hash_enabled_for_type<std::thread::id>();
27+
test_hash_enabled<std::thread::id>();
2828
}
2929

3030
return 0;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ int main(int, char**)
4040
}
4141
#if TEST_STD_VER >= 11
4242
{
43-
test_hash_enabled_for_type<std::shared_ptr<int>>();
44-
test_hash_enabled_for_type<std::shared_ptr<A>>();
43+
test_hash_enabled<std::shared_ptr<int>>();
44+
test_hash_enabled<std::shared_ptr<A>>();
4545
}
4646
#endif
4747

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ void test_enabled_with_deleter() {
3535
using RawDel = typename std::decay<Del>::type;
3636
RawDel d(1);
3737
UPtr p(nullptr, std::forward<Del>(d));
38-
test_hash_enabled_for_type<UPtr>(p);
39-
test_hash_enabled_for_type<pointer>();
38+
test_hash_enabled<UPtr>(p);
39+
test_hash_enabled<pointer>();
4040
}
4141

4242
template <class ValueT, class Del>
4343
void test_disabled_with_deleter() {
4444
using UPtr = std::unique_ptr<ValueT, Del>;
4545
using pointer = typename UPtr::pointer;
46-
test_hash_disabled_for_type<UPtr>();
47-
test_hash_disabled_for_type<pointer>();
46+
test_hash_disabled<UPtr>();
47+
test_hash_disabled<pointer>();
4848
}
4949

5050
template <class T>

libcxx/test/std/utilities/optional/optional.hash/hash.pass.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ int main(int, char**)
6363
assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
6464
}
6565
{
66-
test_hash_enabled_for_type<std::optional<int> >();
67-
test_hash_enabled_for_type<std::optional<int*> >();
68-
test_hash_enabled_for_type<std::optional<const int> >();
69-
test_hash_enabled_for_type<std::optional<int* const> >();
66+
test_hash_enabled<std::optional<int> >();
67+
test_hash_enabled<std::optional<int*> >();
68+
test_hash_enabled<std::optional<const int> >();
69+
test_hash_enabled<std::optional<int* const> >();
7070

71-
test_hash_disabled_for_type<std::optional<A>>();
72-
test_hash_disabled_for_type<std::optional<const A>>();
71+
test_hash_disabled<std::optional<A>>();
72+
test_hash_disabled<std::optional<const A>>();
7373

74-
test_hash_enabled_for_type<std::optional<B>>();
75-
test_hash_enabled_for_type<std::optional<const B>>();
74+
test_hash_enabled<std::optional<B>>();
75+
test_hash_enabled<std::optional<const B>>();
7676
}
7777

7878
return 0;

libcxx/test/std/utilities/template.bitset/bitset.hash/enabled_hash.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
int main(int, char**) {
2323
test_library_hash_specializations_available();
2424
{
25-
test_hash_enabled_for_type<std::bitset<0> >();
26-
test_hash_enabled_for_type<std::bitset<1> >();
27-
test_hash_enabled_for_type<std::bitset<1024> >();
28-
test_hash_enabled_for_type<std::bitset<100000> >();
25+
test_hash_enabled<std::bitset<0> >();
26+
test_hash_enabled<std::bitset<1> >();
27+
test_hash_enabled<std::bitset<1024> >();
28+
test_hash_enabled<std::bitset<100000> >();
2929
}
3030

3131
return 0;

libcxx/test/std/utilities/type.index/type.index.synopsis/hash_type_index.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main(int, char**)
3434
}
3535
#if TEST_STD_VER >= 11
3636
{
37-
test_hash_enabled_for_type<std::type_index>(std::type_index(typeid(int)));
37+
test_hash_enabled<std::type_index>(std::type_index(typeid(int)));
3838
}
3939
#endif
4040

libcxx/test/std/utilities/variant/variant.hash/hash.pass.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void test_hash_monostate() {
103103
static_assert(std::is_copy_constructible<H>::value, "");
104104
}
105105
{
106-
test_hash_enabled_for_type<std::monostate>();
106+
test_hash_enabled<std::monostate>();
107107
}
108108
}
109109

@@ -131,16 +131,16 @@ struct std::hash<B> {
131131

132132
void test_hash_variant_enabled() {
133133
{
134-
test_hash_enabled_for_type<std::variant<int> >();
135-
test_hash_enabled_for_type<std::variant<int*, long, double, const int> >();
134+
test_hash_enabled<std::variant<int> >();
135+
test_hash_enabled<std::variant<int*, long, double, const int> >();
136136
}
137137
{
138-
test_hash_disabled_for_type<std::variant<int, A>>();
139-
test_hash_disabled_for_type<std::variant<const A, void*>>();
138+
test_hash_disabled<std::variant<int, A>>();
139+
test_hash_disabled<std::variant<const A, void*>>();
140140
}
141141
{
142-
test_hash_enabled_for_type<std::variant<int, B>>();
143-
test_hash_enabled_for_type<std::variant<const B, int>>();
142+
test_hash_enabled<std::variant<int, B>>();
143+
test_hash_enabled<std::variant<const B, int>>();
144144
}
145145
}
146146

0 commit comments

Comments
 (0)