[libc++][any] LWG3305: any_cast<void> (#78215)

Implements: https://wg21.link/LWG3305
- https://eel.is/c++draft/any.nonmembers

---------

Co-authored-by: Zingam <zingam@outlook.com>
This commit is contained in:
Hristo Hristov 2024-01-20 06:08:24 +02:00 committed by GitHub
parent ed276dff46
commit 552f5549de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 1 deletions

View File

@ -19,7 +19,7 @@
"","","","","",""
"`2392 <https://wg21.link/LWG2392>`__","""character type"" is used but not defined","Kona November 2023","","",""
"`3203 <https://wg21.link/LWG3203>`__","``span`` element access invalidation","Kona November 2023","","",""
"`3305 <https://wg21.link/LWG3305>`__","``any_cast<void>``","Kona November 2023","","",""
"`3305 <https://wg21.link/LWG3305>`__","``any_cast<void>``","Kona November 2023","|Complete|","18.0",""
"`3431 <https://wg21.link/LWG3431>`__","``<=>`` for containers should require ``three_way_comparable<T>`` instead of ``<=>``","Kona November 2023","","",""
"`3749 <https://wg21.link/LWG3749>`__","``common_iterator`` should handle integer-class difference types","Kona November 2023","","",""
"`3809 <https://wg21.link/LWG3809>`__","Is ``std::subtract_with_carry_engine<uint16_t>`` supposed to work","Kona November 2023","","",""

1 Issue # Issue Name Meeting Status First released version Labels
19
20 `2392 <https://wg21.link/LWG2392>`__ "character type" is used but not defined Kona November 2023
21 `3203 <https://wg21.link/LWG3203>`__ ``span`` element access invalidation Kona November 2023
22 `3305 <https://wg21.link/LWG3305>`__ ``any_cast<void>`` Kona November 2023 |Complete| 18.0
23 `3431 <https://wg21.link/LWG3431>`__ ``<=>`` for containers should require ``three_way_comparable<T>`` instead of ``<=>`` Kona November 2023
24 `3749 <https://wg21.link/LWG3749>`__ ``common_iterator`` should handle integer-class difference types Kona November 2023
25 `3809 <https://wg21.link/LWG3809>`__ Is ``std::subtract_with_carry_engine<uint16_t>`` supposed to work Kona November 2023

View File

@ -98,6 +98,7 @@ namespace std {
#include <__type_traits/is_nothrow_move_constructible.h>
#include <__type_traits/is_reference.h>
#include <__type_traits/is_same.h>
#include <__type_traits/is_void.h>
#include <__type_traits/remove_cv.h>
#include <__type_traits/remove_cvref.h>
#include <__type_traits/remove_reference.h>
@ -555,6 +556,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _ValueType
template <class _ValueType>
inline _LIBCPP_HIDE_FROM_ABI add_pointer_t<add_const_t<_ValueType>> any_cast(any const* __any) _NOEXCEPT {
static_assert(!is_void_v<_ValueType>, "_ValueType may not be void.");
static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference.");
return std::any_cast<_ValueType>(const_cast<any*>(__any));
}
@ -572,6 +574,7 @@ inline _LIBCPP_HIDE_FROM_ABI _RetType __pointer_or_func_cast(void*, /*IsFunction
template <class _ValueType>
_LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any* __any) _NOEXCEPT {
using __any_imp::_Action;
static_assert(!is_void_v<_ValueType>, "_ValueType may not be void.");
static_assert(!is_reference<_ValueType>::value, "_ValueType may not be a reference.");
typedef add_pointer_t<_ValueType> _ReturnType;
if (__any && __any->__h_) {

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// <any>
// template<class T>
// const T* any_cast(const any* operand) noexcept;
// template<class T>
// T* any_cast(any* operand) noexcept;
#include <any>
void test() {
{
const std::any ca = 1;
// expected-error-re@any:* {{static assertion failed{{.*}}_ValueType may not be void.}}
std::any_cast<void>(&ca); // expected-note {{requested here}}
}
{
std::any a = 1;
// expected-error-re@any:* {{static assertion failed{{.*}}_ValueType may not be void.}}
std::any_cast<void>(&a); // expected-note {{requested here}}
}
}