[PATCH] D31234: Implement P0599 - noexcept for hash functions
mclow.lists closed this revision. mclow.lists added a comment. Committed as revision 298573 https://reviews.llvm.org/D31234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31234: Implement P0599 - noexcept for hash functions
EricWF accepted this revision. EricWF added a comment. This revision is now accepted and ready to land. LGTM. Although it would be useful to test that `hash>` and `hash ` do not have noexcept call operators. Alternatively should we make `hash` conditionally noexcept for `variant` and `optional`? https://reviews.llvm.org/D31234 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D31234: Implement P0599 - noexcept for hash functions
mclow.lists updated this revision to Diff 92645. mclow.lists added a comment. Add missing include to the `thread::id` test and mark `unique_ptr`s hash as not noexcept. https://reviews.llvm.org/D31234 Files: include/memory include/optional include/thread include/variant test/std/containers/sequences/vector.bool/vector_bool.pass.cpp test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp test/std/diagnostics/syserr/syserr.hash/error_condition.pass.cpp test/std/strings/basic.string.hash/strings.pass.cpp test/std/strings/string.view/string.view.hash/string_view.pass.cpp test/std/thread/thread.threads/thread.thread.class/thread.thread.id/thread_id.pass.cpp test/std/utilities/function.objects/unord.hash/enum.pass.cpp test/std/utilities/function.objects/unord.hash/floating.pass.cpp test/std/utilities/function.objects/unord.hash/integral.pass.cpp test/std/utilities/function.objects/unord.hash/pointer.pass.cpp test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp test/std/utilities/variant/variant.hash/hash.pass.cpp Index: test/std/utilities/variant/variant.hash/hash.pass.cpp === --- test/std/utilities/variant/variant.hash/hash.pass.cpp +++ test/std/utilities/variant/variant.hash/hash.pass.cpp @@ -102,6 +102,7 @@ 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, ""); } { Index: test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp === --- test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp +++ test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp @@ -30,6 +30,8 @@ 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); Index: test/std/utilities/function.objects/unord.hash/pointer.pass.cpp === --- test/std/utilities/function.objects/unord.hash/pointer.pass.cpp +++ 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 @@ 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 @@ assert(h() != h()); } +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(); } Index: test/std/utilities/function.objects/unord.hash/integral.pass.cpp === --- test/std/utilities/function.objects/unord.hash/integral.pass.cpp +++ test/std/utilities/function.objects/unord.hash/integral.pass.cpp @@ -31,6 +31,7 @@ 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 @@ 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(); Index: test/std/utilities/function.objects/unord.hash/floating.pass.cpp === --- test/std/utilities/function.objects/unord.hash/floating.pass.cpp +++ 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 @@ 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.); Index: test/std/utilities/function.objects/unord.hash/enum.pass.cpp === --- test/std/utilities/function.objects/unord.hash/enum.pass.cpp +++
[PATCH] D31234: Implement P0599 - noexcept for hash functions
mclow.lists created this revision. Mark most of the hash functions provided by libc++ as noexcept; the exceptions being `optional` and `variant`. Tests to ensure this. There's still some investigation to be done on `unique_ptr` and fancy pointer support, but that can come later. https://reviews.llvm.org/D31234 Files: include/optional include/thread include/variant test/std/containers/sequences/vector.bool/vector_bool.pass.cpp test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp test/std/diagnostics/syserr/syserr.hash/error_condition.pass.cpp test/std/strings/basic.string.hash/strings.pass.cpp test/std/strings/string.view/string.view.hash/string_view.pass.cpp test/std/thread/thread.threads/thread.thread.class/thread.thread.id/thread_id.pass.cpp test/std/utilities/function.objects/unord.hash/enum.pass.cpp test/std/utilities/function.objects/unord.hash/floating.pass.cpp test/std/utilities/function.objects/unord.hash/integral.pass.cpp test/std/utilities/function.objects/unord.hash/pointer.pass.cpp test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp test/std/utilities/variant/variant.hash/hash.pass.cpp Index: test/std/utilities/variant/variant.hash/hash.pass.cpp === --- test/std/utilities/variant/variant.hash/hash.pass.cpp +++ test/std/utilities/variant/variant.hash/hash.pass.cpp @@ -102,6 +102,7 @@ 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, ""); } { Index: test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp === --- test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp +++ test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp @@ -30,6 +30,8 @@ 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); Index: test/std/utilities/function.objects/unord.hash/pointer.pass.cpp === --- test/std/utilities/function.objects/unord.hash/pointer.pass.cpp +++ 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 @@ 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 @@ assert(h() != h()); } +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(); } Index: test/std/utilities/function.objects/unord.hash/integral.pass.cpp === --- test/std/utilities/function.objects/unord.hash/integral.pass.cpp +++ test/std/utilities/function.objects/unord.hash/integral.pass.cpp @@ -31,6 +31,7 @@ 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 @@ 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(); Index: test/std/utilities/function.objects/unord.hash/floating.pass.cpp === --- test/std/utilities/function.objects/unord.hash/floating.pass.cpp +++ 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 @@ 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.); Index: test/std/utilities/function.objects/unord.hash/enum.pass.cpp