This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Open status.
Section: 22.7.5 [any.nonmembers] Status: Open Submitter: John Shaw Opened: 2019-10-16 Last modified: 2022-02-05
View other active issues in [any.nonmembers].
View all other issues in [any.nonmembers].
View all issues with Open status.
any foo; void* p = any_cast<void>(&foo);
Per 22.7.5 [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.
[2019-11 Priority to 2 during Monday issue prioritization in Belfast. There is implementation divergence here.]
[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.
[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 22.7.5 [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) , a pointer to the object contained by operand; otherwise, nullptr.[…]