Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libcxx/docs/ReleaseNotes/21.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Deprecations and Removals

- ``std::is_pod`` and ``std::is_pod_v`` are deprecated in C++20 and later.

- libc++ no long adds ``constexpr`` to ``std::hash<std::vector<bool, A>>::operator()``, as the ``constexpr`` addition
since C++20 was an unintended extension.

Upcoming Deprecations and Removals
----------------------------------

Expand Down
7 changes: 3 additions & 4 deletions libcxx/include/__vector/vector_bool.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {

_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}

_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT;
_LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;

friend class __bit_reference<vector>;
friend class __bit_const_reference<vector>;
Expand Down Expand Up @@ -1093,7 +1093,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<bool, _Allocator>::__invariants() cons
}

template <class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT {
size_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT {
size_t __h = 0;
// do middle whole words
size_type __n = __size_;
Expand All @@ -1111,8 +1111,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() con
template <class _Allocator>
struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
: public __unary_function<vector<bool, _Allocator>, size_t> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t
operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT {
_LIBCPP_HIDE_FROM_ABI size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT {
return __vec.__hash_code();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@
#include "test_macros.h"
#include "min_allocator.h"

TEST_CONSTEXPR_CXX20 bool test() {
void test() {
test_hash_enabled<std::vector<bool> >();
test_hash_enabled<std::vector<bool, min_allocator<bool>>>();

return true;
}

int main(int, char**) {
test_library_hash_specializations_available();
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// size_t operator()(T val) const;
// };

// Not very portable

#include <vector>
#include <cassert>
#include <iterator>
Expand All @@ -24,35 +22,29 @@
#include "test_macros.h"
#include "min_allocator.h"

TEST_CONSTEXPR_CXX20 bool tests() {
{
typedef std::vector<bool> T;
typedef std::hash<T> H;
template <class VB>
TEST_CONSTEXPR_CXX20 void test() {
typedef std::hash<VB> H;
#if TEST_STD_VER <= 14
static_assert((std::is_same<H::argument_type, T>::value), "");
static_assert((std::is_same<H::result_type, std::size_t>::value), "");
static_assert((std::is_same<H::argument_type, VB>::value), "");
static_assert((std::is_same<H::result_type, std::size_t>::value), "");
#endif
ASSERT_NOEXCEPT(H()(T()));

bool ba[] = {true, false, true, true, false};
T vb(std::begin(ba), std::end(ba));
H h;
assert(h(vb) != 0);
ASSERT_NOEXCEPT(H()(VB()));

bool ba[] = {true, false, true, true, false};
VB vb(std::begin(ba), std::end(ba));
H h;
if (!TEST_IS_CONSTANT_EVALUATED) {
const std::size_t hash_value = h(vb);
assert(h(vb) == hash_value);
LIBCPP_ASSERT(hash_value != 0);
}
}

TEST_CONSTEXPR_CXX20 bool tests() {
test<std::vector<bool> >();
#if TEST_STD_VER >= 11
{
typedef std::vector<bool, min_allocator<bool>> T;
typedef std::hash<T> H;
# if TEST_STD_VER <= 14
static_assert((std::is_same<H::argument_type, T>::value), "");
static_assert((std::is_same<H::result_type, std::size_t>::value), "");
# endif
ASSERT_NOEXCEPT(H()(T()));
bool ba[] = {true, false, true, true, false};
T vb(std::begin(ba), std::end(ba));
H h;
assert(h(vb) != 0);
}
test<std::vector<bool, min_allocator<bool>>>();
#endif

return true;
Expand Down
Loading