Title
N4089 broke initializing unique_ptr<T[]> from a nullptr
Status
c++17
Section
[unique.ptr.runtime.ctor]
Submitter
Ville Voutilainen

Created on 2015-07-19.00:00:00 last changed 81 months ago

Messages

Date: 2015-11-04.16:49:21

Proposed resolution:

This wording is relative to N4527.

  1. Change [unique.ptr.runtime.ctor] as indicated:

    template <class U> explicit unique_ptr(U p) noexcept;
    template <class U> unique_ptr(U p, see below d) noexcept;
    template <class U> unique_ptr(U p, see below d) noexcept;
    

    -1- These constructors behave the same as the constructors that take a pointer parameter in the primary template except that they shall not participate in overload resolution unless either

    • U is the same type as pointer, or

    • U is nullptr_t, or

    • pointer is the same type as element_type*, U is a pointer type V*, and V(*)[] is convertible to element_type(*)[].

Date: 2015-11-04.16:49:21

[ 2015-10, Kona Saturday afternoon ]

MC: Is it the right fix?

GR: It'd be awefully surprising if we had an interface that accepts null pointer values but not std::nullptr_t. I think the PR is good.

STL: Are any of the assignments and reset affected? [No, they don't operate on explicit {pointer, deleter} pairs.]

VV: This is already shipping, has been implemented, has been tested and works fine.

Move to Tentatively ready.

Date: 2015-07-19.00:00:00

According to the wording in [unique.ptr.runtime.ctor]/1, this won't work:

unique_ptr<int[], DeleterType> x{nullptr, DeleterType{}};

U is not the same type as pointer, so the first bullet will not do.
U is not a pointer type, so the second bullet will not do.

An easy fix would be to add a new bullet after the first bullet, like so:

  • U is the same type as pointer, or

  • U is nullptr_t, or

  • pointer is the same type as element_type*, […]

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2016-03-07 04:11:48adminsetstatus: ready -> wp
2015-11-04 16:49:21adminsetmessages: + msg7612
2015-11-04 16:49:21adminsetstatus: new -> ready
2015-08-17 18:56:18adminsetmessages: + msg7491
2015-07-19 00:00:00admincreate