为什么我不能用reset()删除unique_ptr <char []>?

vll*_*vll 5 c++ c++builder unique-ptr c++11

当我有一个指向单个对象的唯一指针时,我可以删除它reset():

std::unique_ptr<char> variable(new char);
variable.reset();
Run Code Online (Sandbox Code Playgroud)

但是,这不适用于std::unique_ptr包含数组.为什么?删除这样的指针的正确方法是什么?

我正在使用Embarcadero C++ Builder 10.1.相关标准是C++ 11.

我的观察

当我有一个包含数组的唯一指针时,无法编译:

std::unique_ptr<char[]> variable(new char[10]);
variable.reset();
Run Code Online (Sandbox Code Playgroud)

错误信息是no matching function to call for 'reset'.

这也失败了:

std::unique_ptr<char[]> variable(new char[10]);
variable.reset(nullptr);
Run Code Online (Sandbox Code Playgroud)

错误消息是cannot initialize a variable of type 'pointer' (aka 'char *') with an lvalue of type '<bound member function type>'和assigning to '<bound member function type>' from incompatible type '_Null_ptr_type' (aka 'nullptr_t').

这编译:

std::unique_ptr<char[]> variable(new char[10]);
variable = nullptr;
Run Code Online (Sandbox Code Playgroud)

来自<memory>的相关代码

template<class _Uty>
using _Enable_ctor_reset = enable_if_t<
    is_same<_Uty, pointer>::value
    || (is_same<pointer, element_type *>::value
    && is_pointer<_Uty>::value
    && is_convertible<
        remove_pointer_t<_Uty>(*)[],
        element_type(*)[]
    >::value)>;

_Myt& operator=(_Null_ptr_type) _NOEXCEPT
    {   // assign a null pointer
    reset(pointer());
    return (*this);
    }

_NOINLINE void reset(_Null_ptr_type _Ptr) _NOEXCEPT
    {   // establish new null pointer
    pointer _Old = this->_Myptr;
    this->_Myptr = _Ptr;
    if (_Old != pointer())
        this->get_deleter()(_Old);
    }

template<class _Uty,
    class = _Enable_ctor_reset<_Uty> >
void reset(_Uty _Ptr) _NOEXCEPT
    {   // establish new pointer
    pointer _Old = get();
    this->_Myptr() = _Ptr;
    if (_Old != pointer())
        this->get_deleter()(_Old);
    }
Run Code Online (Sandbox Code Playgroud)

vll*_*vll 1

这似乎是标准库中的一个错误,因为正如deW1和sanjay在评论中指出的那样,相同的代码可以使用其他编译器进行编译。

C++11 标准,第 20.7.1.3 节(“具有运行时长度的数组对象的 unique_ptr”)列出了reset()以下签名:

void Reset(指针 p = 指针()) noexcept;

第一个示例无法编译,因为标准库实现中缺少默认参数。第二个示例本质上调用了reset(pointer()),但它无法编译。可能这个编译错误是未添加默认参数的原因。

我已向 Embarcadero 提交了错误报告:

RSP-16165 在包含数组对象的 unique_ptr 上调用 reset() 时出现编译错误