From 5f653decf496dfdfdc714f1e022f0e00dd997e1e Mon Sep 17 00:00:00 2001 From: redi Date: Thu, 23 Mar 2017 19:40:16 +0000 Subject: [PATCH] Implement LWG 2686, std::hash, for C++17 2017-03-23 Daniel Kruegler Implement LWG 2686, Why is std::hash specialized for error_code, but not error_condition? * include/std/system_error (hash): Define for C++17. * testsuite/20_util/hash/operators/size_t.cc (hash): Instantiate test for error_condition. * testsuite/20_util/hash/requirements/explicit_instantiation.cc (hash): Instantiate hash. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@246424 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 8 ++++++++ libstdc++-v3/include/std/system_error | 22 ++++++++++++++++++---- .../testsuite/20_util/hash/operators/size_t.cc | 3 +++ .../hash/requirements/explicit_instantiation.cc | 3 +++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b3e3fe2ba56..1425d28f7f2 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,13 @@ 2017-03-23 Daniel Kruegler + Implement LWG 2686, Why is std::hash specialized for error_code, + but not error_condition? + * include/std/system_error (hash): Define for C++17. + * testsuite/20_util/hash/operators/size_t.cc (hash): + Instantiate test for error_condition. + * testsuite/20_util/hash/requirements/explicit_instantiation.cc + (hash): Instantiate hash. + * include/bits/c++config (_GLIBCXX17_INLINE): Define. * include/bits/regex_constants.h (All std::regex_constants constants): Add _GLIBCXX17_INLINE as per P0607R0. diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index 6775a6ea757..ec7d25f25f7 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -373,14 +373,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION } // namespace -#ifndef _GLIBCXX_COMPATIBILITY_CXX0X - #include namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +#ifndef _GLIBCXX_COMPATIBILITY_CXX0X // DR 1182. /// std::hash specialization for error_code. template<> @@ -394,12 +393,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp); } }; +#endif // _GLIBCXX_COMPATIBILITY_CXX0X + +#if __cplusplus > 201402L + // DR 2686. + /// std::hash specialization for error_condition. + template<> + struct hash + : public __hash_base + { + size_t + operator()(const error_condition& __e) const noexcept + { + const size_t __tmp = std::_Hash_impl::hash(__e.value()); + return std::_Hash_impl::__hash_combine(__e.category(), __tmp); + } + }; +#endif _GLIBCXX_END_NAMESPACE_VERSION } // namespace -#endif // _GLIBCXX_COMPATIBILITY_CXX0X - #endif // C++11 #endif // _GLIBCXX_SYSTEM_ERROR diff --git a/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc b/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc index ad028436889..cc191d6f9a7 100644 --- a/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc +++ b/libstdc++-v3/testsuite/20_util/hash/operators/size_t.cc @@ -43,6 +43,9 @@ template void test01() { do_test(); +#if __cplusplus > 201402L + do_test(); +#endif } int main() diff --git a/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc index e9e5ea1ef2b..d01829af56f 100644 --- a/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc +++ b/libstdc++-v3/testsuite/20_util/hash/requirements/explicit_instantiation.cc @@ -40,6 +40,9 @@ template class std::hash; template class std::hash; template class std::hash; template class std::hash; +#if __cplusplus > 201402L +template class std::hash; +#endif #ifdef _GLIBCXX_USE_WCHAR_T template class std::hash; -- 2.11.4.GIT