Title
Apparently redundant requirement for dynamic_pointer_cast
Status
c++20
Section
[util.smartptr.shared.cast]
Submitter
Tim Song

Created on 2017-05-11.00:00:00 last changed 46 months ago

Messages

Date: 2017-07-12.01:30:31

Proposed resolution:

This wording is relative to N4659.

  1. Edit [util.smartptr.shared.cast] as indicated:

    shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;
    

    -4- Requires: The expression dynamic_cast<T*>((U*)0) shall be well formed. The expression dynamic_cast<typename shared_ptr<T>::element_type*>(r.get()) shall be well formed and shall have well defined behavior.

    […]

Date: 2017-07-12.01:30:31

[ 2017-07 Toronto Monday issue prioritization ]

Priority 0; move to Ready

Date: 2017-05-11.00:00:00

Currently [util.smartptr.shared.cast]/4 says:

Requires: The expression dynamic_cast<T*>((U*)nullptr) shall be well formed and shall have well defined behavior.

A dynamic_cast of a null pointer, if well-formed, always has well-defined behavior: it returns a null pointer. The second part is therefore redundant as currently worded. The C++14 version, on the other hand, requires dynamic_cast<T*>(r.get()) to have well-defined behavior, which actually adds something: it requires the user to not trigger the undefined case in [class.cdtor]/5, for instance.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2017-11-13 19:01:36adminsetstatus: voting -> wp
2017-10-17 18:34:55adminsetstatus: ready -> voting
2017-07-12 01:30:31adminsetmessages: + msg9332
2017-07-12 01:30:31adminsetstatus: new -> ready
2017-05-13 16:25:22adminsetmessages: + msg9183
2017-05-11 00:00:00admincreate