Created on 2019-10-16.00:00:00 last changed 24 months ago
Proposed resolution:
This wording is relative to N4950.
Modify [any.nonmembers] as indicated:
template<class T> const T* any_cast(const any* operand) noexcept; template<class T> T* any_cast(any* operand) noexcept;-8- Mandates:
is_void_v<T>isfalse.-9- Returns: If operand != nullptr && operand->type() == typeid(T) is
[…]true, a pointer to the object contained by operand; otherwise, nullptr.
[ 2023-11-11 Approved at November 2023 meeting in Kona. Status changed: Voting → WP. ]
[ 2023-06-14 Varna; Move to Ready ]
Poll: 7-0-1
[ 2023-06-14 Varna; Jonathan provides improved wording ]
[ 2022-02 Currently ill-formed in MSVC ("error C2338: std::any cannot contain void") and returns null pointer in libstdc++ and libc++. ]
This wording is relative to N4835.
Modify [any.nonmembers] as indicated:
template<class T> const T* any_cast(const any* operand) noexcept; template<class T> T* any_cast(any* operand) noexcept;-9- Returns: If operand != nullptr && operand->type() == typeid(T) && is_object_v<T>, a pointer to the object contained by operand; otherwise, nullptr.
[…]
[ 2020-02 LWG discussion in Prague did not reach consensus. Status to Open. ]
There was discussion about whether or not any_cast<void>(a) should be ill-formed, or return nullptr.
Poll "should it return nullptr" was 0-4-5-5-1.
[ 2019-11 Priority to 2 during Monday issue prioritization in Belfast. There is implementation divergence here. ]
any foo; void* p = any_cast<void>(&foo);
Per [any.nonmembers]/9, since the operand isn't nullptr and operand->type() == typeid(T) (because T = void in this case), we should return a pointer to the object contained by operand. But there is no such object.
We need to handle the T = void case, probably by just explicitly returning nullptr.| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2023-11-13 14:08:10 | admin | set | messages: + msg13836 |
| 2023-11-13 14:08:10 | admin | set | status: voting -> wp |
| 2023-11-07 21:41:54 | admin | set | status: ready -> voting |
| 2023-06-14 07:38:05 | admin | set | messages: + msg13631 |
| 2023-06-14 07:38:05 | admin | set | status: open -> ready |
| 2023-06-14 07:34:48 | admin | set | messages: + msg13630 |
| 2022-02-03 00:31:03 | admin | set | messages: + msg12336 |
| 2020-02-14 06:55:06 | admin | set | messages: + msg11093 |
| 2020-02-14 06:55:06 | admin | set | status: new -> open |
| 2019-11-04 13:23:43 | admin | set | messages: + msg10725 |
| 2019-10-19 20:23:42 | admin | set | messages: + msg10707 |
| 2019-10-16 00:00:00 | admin | create | |