Implement P0513R0 - "Poisoning the Hash"

Summary:
Exactly what the title says.

This patch also adds a `std::hash<nullptr_t>` specialization in C++17, but it was not added by this paper and I can't find the actual paper that adds it.

See http://wg21.link/P0513R0 for more info.

If there are no comments in the next couple of days I'll commit this

Reviewers: mclow.lists, K-ballo, EricWF

Reviewed By: EricWF

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D28938

llvm-svn: 292684
diff --git a/libcxx/include/optional b/libcxx/include/optional
index c002cc7..b13a2d5 100644
--- a/libcxx/include/optional
+++ b/libcxx/include/optional
@@ -1295,7 +1295,9 @@
 }
 
 template <class _Tp>
-struct _LIBCPP_TEMPLATE_VIS hash<optional<_Tp> >
+struct _LIBCPP_TEMPLATE_VIS hash<
+    __enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>>
+>
 {
     typedef optional<_Tp> argument_type;
     typedef size_t        result_type;
@@ -1303,7 +1305,7 @@
     _LIBCPP_INLINE_VISIBILITY
     result_type operator()(const argument_type& __opt) const _NOEXCEPT
     {
-        return static_cast<bool>(__opt) ? hash<_Tp>()(*__opt) : 0;
+        return static_cast<bool>(__opt) ? hash<remove_const_t<_Tp>>()(*__opt) : 0;
     }
 };