diff --git a/include/memory b/include/memory index c7f540bb8..8ef458802 100644 --- a/include/memory +++ b/include/memory @@ -3037,7 +3037,7 @@ struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< typedef unique_ptr<_Tp, _Dp> argument_type; typedef size_t result_type; _LIBCPP_INLINE_VISIBILITY - result_type operator()(const argument_type& __ptr) const _NOEXCEPT + result_type operator()(const argument_type& __ptr) const { typedef typename argument_type::pointer pointer; return hash()(__ptr.get()); diff --git a/include/optional b/include/optional index 180f63ffc..002842f5b 100644 --- a/include/optional +++ b/include/optional @@ -1301,7 +1301,7 @@ struct _LIBCPP_TEMPLATE_VIS hash< typedef size_t result_type; _LIBCPP_INLINE_VISIBILITY - result_type operator()(const argument_type& __opt) const _NOEXCEPT + result_type operator()(const argument_type& __opt) const { return static_cast(__opt) ? hash>()(*__opt) : 0; } diff --git a/include/thread b/include/thread index 94c77e0cb..874ce3ec1 100644 --- a/include/thread +++ b/include/thread @@ -261,7 +261,7 @@ struct _LIBCPP_TEMPLATE_VIS hash<__thread_id> : public unary_function<__thread_id, size_t> { _LIBCPP_INLINE_VISIBILITY - size_t operator()(__thread_id __v) const + size_t operator()(__thread_id __v) const _NOEXCEPT { return hash<__libcpp_thread_id>()(__v.__id_); } diff --git a/include/variant b/include/variant index 099e6c358..33f88e057 100644 --- a/include/variant +++ b/include/variant @@ -1562,7 +1562,7 @@ struct _LIBCPP_TEMPLATE_VIS hash { using result_type = size_t; inline _LIBCPP_INLINE_VISIBILITY - result_type operator()(const argument_type&) const { + result_type operator()(const argument_type&) const _NOEXCEPT { return 66740831; // return a fundamentally attractive random value. } }; diff --git a/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp b/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp index 4f82792fa..64104a40e 100644 --- a/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp +++ b/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp @@ -31,7 +31,8 @@ int main() typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); - + ASSERT_NOEXCEPT(H()(T())); + bool ba[] = {true, false, true, true, false}; T vb(std::begin(ba), std::end(ba)); H h; @@ -43,6 +44,7 @@ int main() typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); bool ba[] = {true, false, true, true, false}; T vb(std::begin(ba), std::end(ba)); H h; diff --git a/test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp b/test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp index 4091f446a..dac13bdb8 100644 --- a/test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp +++ b/test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp @@ -29,6 +29,7 @@ test(int i) typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); H h; T ec(i, std::system_category()); const std::size_t result = h(ec); diff --git a/test/std/diagnostics/syserr/syserr.hash/error_condition.pass.cpp b/test/std/diagnostics/syserr/syserr.hash/error_condition.pass.cpp index d455210c2..eef37c68b 100644 --- a/test/std/diagnostics/syserr/syserr.hash/error_condition.pass.cpp +++ b/test/std/diagnostics/syserr/syserr.hash/error_condition.pass.cpp @@ -29,6 +29,7 @@ test(int i) typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); H h; T ec(i, std::system_category()); const std::size_t result = h(ec); diff --git a/test/std/strings/basic.string.hash/strings.pass.cpp b/test/std/strings/basic.string.hash/strings.pass.cpp index 5fc32c06a..d74e48575 100644 --- a/test/std/strings/basic.string.hash/strings.pass.cpp +++ b/test/std/strings/basic.string.hash/strings.pass.cpp @@ -22,6 +22,8 @@ #include #include +#include "test_macros.h" + template void test() @@ -29,6 +31,8 @@ test() typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); + H h; std::string g1 = "1234567890"; std::string g2 = "1234567891"; diff --git a/test/std/strings/string.view/string.view.hash/string_view.pass.cpp b/test/std/strings/string.view/string.view.hash/string_view.pass.cpp index d07664825..53c3d261d 100644 --- a/test/std/strings/string.view/string.view.hash/string_view.pass.cpp +++ b/test/std/strings/string.view/string.view.hash/string_view.pass.cpp @@ -23,6 +23,8 @@ #include #include +#include "test_macros.h" + using std::string_view; template @@ -36,6 +38,7 @@ test() typedef typename SV::value_type char_type; typedef std::basic_string String; typedef std::hash SH; + ASSERT_NOEXCEPT(H()(SV())); char_type g1 [ 10 ]; char_type g2 [ 10 ]; diff --git a/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/thread_id.pass.cpp b/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/thread_id.pass.cpp index f7d4deb8f..4f1491dec 100644 --- a/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/thread_id.pass.cpp +++ b/test/std/thread/thread.threads/thread.thread.class/thread.thread.id/thread_id.pass.cpp @@ -23,6 +23,8 @@ #include #include +#include "test_macros.h" + int main() { std::thread::id id1; @@ -30,6 +32,7 @@ int main() typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(id2)); H h; assert(h(id1) != h(id2)); } diff --git a/test/std/utilities/function.objects/unord.hash/enum.pass.cpp b/test/std/utilities/function.objects/unord.hash/enum.pass.cpp index 09ea034b7..a7ddd9a49 100644 --- a/test/std/utilities/function.objects/unord.hash/enum.pass.cpp +++ b/test/std/utilities/function.objects/unord.hash/enum.pass.cpp @@ -36,6 +36,7 @@ test() typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); typedef typename std::underlying_type::type under_type; H h1; diff --git a/test/std/utilities/function.objects/unord.hash/floating.pass.cpp b/test/std/utilities/function.objects/unord.hash/floating.pass.cpp index 643e2d8c5..e67aa016c 100644 --- a/test/std/utilities/function.objects/unord.hash/floating.pass.cpp +++ b/test/std/utilities/function.objects/unord.hash/floating.pass.cpp @@ -24,6 +24,8 @@ #include #include +#include "test_macros.h" + template void test() @@ -31,6 +33,7 @@ test() typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); H h; std::size_t t0 = h(0.); diff --git a/test/std/utilities/function.objects/unord.hash/integral.pass.cpp b/test/std/utilities/function.objects/unord.hash/integral.pass.cpp index 08a2a8c71..ce87f5918 100644 --- a/test/std/utilities/function.objects/unord.hash/integral.pass.cpp +++ b/test/std/utilities/function.objects/unord.hash/integral.pass.cpp @@ -31,6 +31,7 @@ test() typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); H h; for (int i = 0; i <= 5; ++i) @@ -64,42 +65,42 @@ int main() test(); test(); -// LWG #2119 +// LWG #2119 test(); test(); - test(); - test(); - test(); - test(); + test(); + test(); + test(); + test(); - test(); - test(); - test(); - test(); + test(); + test(); + test(); + test(); - test(); - test(); - test(); - test(); + test(); + test(); + test(); + test(); test(); test(); - test(); - test(); - test(); - test(); + test(); + test(); + test(); + test(); - test(); - test(); - test(); - test(); + test(); + test(); + test(); + test(); - test(); - test(); - test(); - test(); + test(); + test(); + test(); + test(); test(); test(); diff --git a/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp b/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp index a48394495..d71514b52 100644 --- a/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp +++ b/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp @@ -23,6 +23,8 @@ #include #include +#include "test_macros.h" + template void test() @@ -30,6 +32,7 @@ test() typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); H h; typedef typename std::remove_pointer::type type; @@ -38,7 +41,17 @@ test() assert(h(&i) != h(&j)); } +void test_nullptr() +{ + typedef std::nullptr_t T; + typedef std::hash H; + static_assert((std::is_same::value), "" ); + static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); +} + int main() { test(); + test_nullptr(); } diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp index 879ea405c..b539e6380 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp @@ -67,6 +67,7 @@ int main() int* ptr = new int; std::unique_ptr p(ptr); std::hash > f; + ASSERT_NOT_NOEXCEPT(f(p)); std::size_t h = f(p); assert(h == std::hash()(ptr)); } diff --git a/test/std/utilities/optional/optional.hash/hash.pass.cpp b/test/std/utilities/optional/optional.hash/hash.pass.cpp index ea89dc3bd..8f94d6be6 100644 --- a/test/std/utilities/optional/optional.hash/hash.pass.cpp +++ b/test/std/utilities/optional/optional.hash/hash.pass.cpp @@ -36,6 +36,7 @@ int main() { typedef int T; optional opt; + ASSERT_NOT_NOEXCEPT(std::hash>()(opt)); assert(std::hash>{}(opt) == nullopt_hash); opt = 2; assert(std::hash>{}(opt) == std::hash{}(*opt)); @@ -43,6 +44,7 @@ int main() { typedef std::string T; optional opt; + ASSERT_NOT_NOEXCEPT(std::hash>()(opt)); assert(std::hash>{}(opt) == nullopt_hash); opt = std::string("123"); assert(std::hash>{}(opt) == std::hash{}(*opt)); @@ -50,6 +52,7 @@ int main() { typedef std::unique_ptr T; optional opt; + ASSERT_NOT_NOEXCEPT(std::hash>()(opt)); assert(std::hash>{}(opt) == nullopt_hash); opt = std::unique_ptr(new int(3)); assert(std::hash>{}(opt) == std::hash{}(*opt)); diff --git a/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp b/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp index bc6507891..8eab082cf 100644 --- a/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp @@ -30,6 +30,8 @@ test() typedef std::hash H; static_assert((std::is_same::value), "" ); static_assert((std::is_same::value), "" ); + ASSERT_NOEXCEPT(H()(T())); + H h; T bs(static_cast(N)); const std::size_t result = h(bs); diff --git a/test/std/utilities/variant/variant.hash/hash.pass.cpp b/test/std/utilities/variant/variant.hash/hash.pass.cpp index 96ef967f6..840084fe8 100644 --- a/test/std/utilities/variant/variant.hash/hash.pass.cpp +++ b/test/std/utilities/variant/variant.hash/hash.pass.cpp @@ -102,6 +102,7 @@ void test_hash_monostate() { assert(h(m1) == h(m2)); { ASSERT_SAME_TYPE(decltype(h(m1)), std::size_t); + ASSERT_NOEXCEPT(h(m1)); static_assert(std::is_copy_constructible::value, ""); } {