Skip to content

[libc++] Deprecate and remove member types of hash in <variant> #127758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions libcxx/include/__variant/monostate.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(monostate, monostate) noe

template <>
struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
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.
}
};
Expand Down
8 changes: 5 additions & 3 deletions libcxx/include/variant
Original file line number Diff line number Diff line change
Expand Up @@ -1585,10 +1585,12 @@ swap(variant<_Types...>& __lhs,

template <class... _Types>
struct _LIBCPP_TEMPLATE_VIS hash< __enable_hash_helper<variant<_Types...>, 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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <variant>

#include "test_macros.h"

using A1 [[maybe_unused]] = std::hash<std::variant<int, long>>::argument_type;
using R1 [[maybe_unused]] = std::hash<std::variant<int, long>>::result_type;
#if TEST_STD_VER >= 20
// expected-error@-3 {{no type named 'argument_type' in 'std::hash<std::variant<int, long>>'}}
// expected-error@-3 {{no type named 'result_type' in 'std::hash<std::variant<int, long>>'}}
#else
// expected-warning@-6 {{'argument_type' is deprecated}}
// expected-warning@-6 {{'result_type' is deprecated}}
#endif

using A2 [[maybe_unused]] = std::hash<std::monostate>::argument_type;
using R2 [[maybe_unused]] = std::hash<std::monostate>::result_type;
#if TEST_STD_VER >= 20
// expected-error@-3 {{no type named 'argument_type' in 'std::hash<monostate>'}}
// expected-error@-3 {{no type named 'result_type' in 'std::hash<monostate>'}}
#else
// expected-warning@-6 {{'argument_type' is deprecated}}
// expected-warning@-6 {{'result_type' is deprecated}}
#endif