summaryrefslogtreecommitdiff
path: root/test/std/utilities/function.objects/unord.hash
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/utilities/function.objects/unord.hash')
-rw-r--r--test/std/utilities/function.objects/unord.hash/enabled_hashes.pass.cpp23
-rw-r--r--test/std/utilities/function.objects/unord.hash/enum.pass.cpp4
-rw-r--r--test/std/utilities/function.objects/unord.hash/floating.pass.cpp3
-rw-r--r--test/std/utilities/function.objects/unord.hash/integral.pass.cpp54
-rw-r--r--test/std/utilities/function.objects/unord.hash/pointer.pass.cpp16
5 files changed, 73 insertions, 27 deletions
diff --git a/test/std/utilities/function.objects/unord.hash/enabled_hashes.pass.cpp b/test/std/utilities/function.objects/unord.hash/enabled_hashes.pass.cpp
new file mode 100644
index 0000000000000..775247fc80b68
--- /dev/null
+++ b/test/std/utilities/function.objects/unord.hash/enabled_hashes.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <functional>
+
+// Test that <functional> provides all of the arithmetic, enum, and pointer
+// hash specializations.
+
+#include <functional>
+
+#include "poisoned_hash_helper.hpp"
+
+int main() {
+ test_library_hash_specializations_available();
+}
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 af367789a105b..a7ddd9a499977 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<T> H;
static_assert((std::is_same<typename H::argument_type, T>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
+ ASSERT_NOEXCEPT(H()(T()));
typedef typename std::underlying_type<T>::type under_type;
H h1;
@@ -43,7 +44,8 @@ test()
for (int i = 0; i <= 5; ++i)
{
T t(static_cast<T> (i));
- if (sizeof(T) <= sizeof(std::size_t))
+ const bool small = std::integral_constant<bool, sizeof(T) <= sizeof(std::size_t)>::value; // avoid compiler warnings
+ if (small)
assert(h1(t) == h2(static_cast<under_type>(i)));
}
}
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 643e2d8c5d860..e67aa016c1e74 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 <limits>
#include <cmath>
+#include "test_macros.h"
+
template <class T>
void
test()
@@ -31,6 +33,7 @@ test()
typedef std::hash<T> H;
static_assert((std::is_same<typename H::argument_type, T>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::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 2f3f9bee4bc36..ce87f5918b20b 100644
--- a/test/std/utilities/function.objects/unord.hash/integral.pass.cpp
+++ b/test/std/utilities/function.objects/unord.hash/integral.pass.cpp
@@ -31,12 +31,14 @@ test()
typedef std::hash<T> H;
static_assert((std::is_same<typename H::argument_type, T>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
+ ASSERT_NOEXCEPT(H()(T()));
H h;
for (int i = 0; i <= 5; ++i)
{
T t(static_cast<T>(i));
- if (sizeof(T) <= sizeof(std::size_t))
+ const bool small = std::integral_constant<bool, sizeof(T) <= sizeof(std::size_t)>::value; // avoid compiler warnings
+ if (small)
{
const std::size_t result = h(t);
LIBCPP_ASSERT(result == static_cast<size_t>(t));
@@ -63,42 +65,42 @@ int main()
test<long long>();
test<unsigned long long>();
-// LWG #2119
+// LWG #2119
test<std::ptrdiff_t>();
test<size_t>();
- test<int8_t>();
- test<int16_t>();
- test<int32_t>();
- test<int64_t>();
+ test<int8_t>();
+ test<int16_t>();
+ test<int32_t>();
+ test<int64_t>();
- test<int_fast8_t>();
- test<int_fast16_t>();
- test<int_fast32_t>();
- test<int_fast64_t>();
+ test<int_fast8_t>();
+ test<int_fast16_t>();
+ test<int_fast32_t>();
+ test<int_fast64_t>();
- test<int_least8_t>();
- test<int_least16_t>();
- test<int_least32_t>();
- test<int_least64_t>();
+ test<int_least8_t>();
+ test<int_least16_t>();
+ test<int_least32_t>();
+ test<int_least64_t>();
test<intmax_t>();
test<intptr_t>();
- test<uint8_t>();
- test<uint16_t>();
- test<uint32_t>();
- test<uint64_t>();
+ test<uint8_t>();
+ test<uint16_t>();
+ test<uint32_t>();
+ test<uint64_t>();
- test<uint_fast8_t>();
- test<uint_fast16_t>();
- test<uint_fast32_t>();
- test<uint_fast64_t>();
+ test<uint_fast8_t>();
+ test<uint_fast16_t>();
+ test<uint_fast32_t>();
+ test<uint_fast64_t>();
- test<uint_least8_t>();
- test<uint_least16_t>();
- test<uint_least32_t>();
- test<uint_least64_t>();
+ test<uint_least8_t>();
+ test<uint_least16_t>();
+ test<uint_least32_t>();
+ test<uint_least64_t>();
test<uintmax_t>();
test<uintptr_t>();
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 a48394495e2d5..36280a38e0a7f 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 <type_traits>
#include <limits>
+#include "test_macros.h"
+
template <class T>
void
test()
@@ -30,6 +32,7 @@ test()
typedef std::hash<T> H;
static_assert((std::is_same<typename H::argument_type, T>::value), "" );
static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
+ ASSERT_NOEXCEPT(H()(T()));
H h;
typedef typename std::remove_pointer<T>::type type;
@@ -38,7 +41,20 @@ test()
assert(h(&i) != h(&j));
}
+// can't hash nullptr_t until c++17
+void test_nullptr()
+{
+#if TEST_STD_VER > 14
+ typedef std::nullptr_t T;
+ typedef std::hash<T> H;
+ static_assert((std::is_same<typename H::argument_type, T>::value), "" );
+ static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
+ ASSERT_NOEXCEPT(H()(T()));
+#endif
+}
+
int main()
{
test<int*>();
+ test_nullptr();
}