diff --git a/libcxx/include/__variant/monostate.h b/libcxx/include/__variant/monostate.h index c5d2dacaf4205..b29bbdf5cdbe4 100644 --- a/libcxx/include/__variant/monostate.h +++ b/libcxx/include/__variant/monostate.h @@ -49,10 +49,12 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(monostate, monostate) noe template <> struct _LIBCPP_TEMPLATE_VIS hash { - using argument_type = monostate; - using result_type = size_t; +# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using argument_type _LIBCPP_DEPRECATED_IN_CXX17 = monostate; + using result_type _LIBCPP_DEPRECATED_IN_CXX17 = size_t; +# endif - inline _LIBCPP_HIDE_FROM_ABI result_type operator()(const argument_type&) const _NOEXCEPT { + inline _LIBCPP_HIDE_FROM_ABI size_t operator()(const monostate&) const noexcept { return 66740831; // return a fundamentally attractive random value. } }; diff --git a/libcxx/include/variant b/libcxx/include/variant index 3786d9524020b..9998d4a457715 100644 --- a/libcxx/include/variant +++ b/libcxx/include/variant @@ -1585,10 +1585,12 @@ swap(variant<_Types...>& __lhs, template struct _LIBCPP_TEMPLATE_VIS hash< __enable_hash_helper, remove_const_t<_Types>...>> { - using argument_type = variant<_Types...>; - using result_type = size_t; +# if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) + using argument_type _LIBCPP_DEPRECATED_IN_CXX17 = variant<_Types...>; + using result_type _LIBCPP_DEPRECATED_IN_CXX17 = size_t; +# endif - _LIBCPP_HIDE_FROM_ABI result_type operator()(const argument_type& __v) const { + _LIBCPP_HIDE_FROM_ABI size_t operator()(const variant<_Types...>& __v) const { using __variant_detail::__visitation::__variant; size_t __res = __v.valueless_by_exception() diff --git a/libcxx/test/std/utilities/variant/variant.hash/hash.depr.verify.cpp b/libcxx/test/std/utilities/variant/variant.hash/hash.depr.verify.cpp new file mode 100644 index 0000000000000..9b22cbda9f345 --- /dev/null +++ b/libcxx/test/std/utilities/variant/variant.hash/hash.depr.verify.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: std-at-least-c++17 + +#include + +#include "test_macros.h" + +using A1 [[maybe_unused]] = std::hash>::argument_type; +using R1 [[maybe_unused]] = std::hash>::result_type; +#if TEST_STD_VER >= 20 +// expected-error@-3 {{no type named 'argument_type' in 'std::hash>'}} +// expected-error@-3 {{no type named 'result_type' in 'std::hash>'}} +#else +// expected-warning@-6 {{'argument_type' is deprecated}} +// expected-warning@-6 {{'result_type' is deprecated}} +#endif + +using A2 [[maybe_unused]] = std::hash::argument_type; +using R2 [[maybe_unused]] = std::hash::result_type; +#if TEST_STD_VER >= 20 +// expected-error@-3 {{no type named 'argument_type' in 'std::hash'}} +// expected-error@-3 {{no type named 'result_type' in 'std::hash'}} +#else +// expected-warning@-6 {{'argument_type' is deprecated}} +// expected-warning@-6 {{'result_type' is deprecated}} +#endif