From: Daniel Kruegler Date: Thu, 23 Mar 2017 19:40:16 +0000 (+0000) Subject: Implement LWG 2686, std::hash, for C++17 X-Git-Tag: basepoints/gcc-8~358 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f359d19d0b1b13c21e7a325ef391ed19bc8ba70;p=thirdparty%2Fgcc.git 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. From-SVN: r246424 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b3e3fe2ba561..1425d28f7f29 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 6775a6ea757e..ec7d25f25f79 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 ad0284368894..cc191d6f9a74 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 e9e5ea1ef2bc..d01829af56f3 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;