Index: include/functional =================================================================== --- include/functional +++ include/functional @@ -2574,12 +2574,11 @@ }; #if _LIBCPP_STD_VER > 11 -template -struct _LIBCPP_TYPE_VIS_ONLY hash + +template ::value> +struct _LIBCPP_TYPE_VIS_ONLY __enum_hash : public unary_function<_Tp, size_t> { - static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types"); - _LIBCPP_INLINE_VISIBILITY size_t operator()(_Tp __v) const _NOEXCEPT { @@ -2587,6 +2586,17 @@ return hash{}(static_cast(__v)); } }; +template +struct _LIBCPP_TYPE_VIS_ONLY __enum_hash<_Tp, false> { + __enum_hash() = delete; + __enum_hash(__enum_hash const&) = delete; + __enum_hash& operator=(__enum_hash const&) = delete; +}; + +template +struct _LIBCPP_TYPE_VIS_ONLY hash : public __enum_hash<_Tp> +{ +}; #endif Index: test/std/utilities/function.objects/unord.hash/enum.pass.cpp =================================================================== --- test/std/utilities/function.objects/unord.hash/enum.pass.cpp +++ test/std/utilities/function.objects/unord.hash/enum.pass.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +// UNSUPPORTED: c++98, c++03, c++11 + // // make sure that we can hash enumeration values @@ -14,8 +16,6 @@ #include "test_macros.h" -#if TEST_STD_VER >= 14 - #include #include #include @@ -59,6 +59,3 @@ test(); } -#else -int main () {} -#endif Index: test/std/utilities/function.objects/unord.hash/non_enum.pass.cpp =================================================================== --- /dev/null +++ test/std/utilities/function.objects/unord.hash/non_enum.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// Hashing a struct w/o a defined hash should *not* fail, but it should +// create a type that is not constructible and not callable. +// See also: http://cplusplus.github.io/LWG/lwg-active.html#2543 + +#include +#include +#include + +#include "test_macros.h" + +struct X {}; + +int main() +{ + using H = std::hash; + static_assert(!std::is_default_constructible::value, ""); + static_assert(!std::is_copy_constructible::value, ""); + static_assert(!std::is_move_constructible::value, ""); + static_assert(!std::is_copy_assignable::value, ""); + static_assert(!std::is_move_assignable::value, ""); +#if TEST_STD_VER > 14 + static_assert(!std::is_callable::value, ""); + static_assert(!std::is_callable::value, ""); +#endif +}