Title
any_cast<void>
Status
new
Section
[any.nonmembers]
Submitter
John Shaw

Created on 2019-10-16.00:00:00, last changed 2019-11-04.13:23:43.

Messages

Date: 2019-11-04.13:23:43

Proposed resolution:

This wording is relative to N4835.

  1. 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.

    […]

Date: 2019-11-04.13:23:43

[ 2019-11 Priority to 2 during Monday issue prioritization in Belfast. There is implementation divergence here. ]

Date: 2019-10-16.00:00:00
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
2019-11-04 13:23:43adminsetmessages: + msg10725
2019-10-19 20:23:42adminsetmessages: + msg10707
2019-10-16 00:00:00admincreate