http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51609

             Bug #: 51609
           Summary: [C++11] unique_ptr<const T[]>::reset rejects
                    cv-compatible argument pointers
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: daniel.krueg...@googlemail.com


gcc 4.7.0 20111210 (experimental) in C++0x mode rejects the following code: 

//---------------
#include <memory>

struct T {};

T* bar() { return new T{}; }

int main()
{
  std::unique_ptr<const T[]> p;
  p.reset(bar()); // # Line 10
}
//---------------

"main.cpp||In function 'int main()':|
main.cpp|10|error: use of deleted function 'void std::unique_ptr<_Tp [],
_Dp>::reset(_Up) [with _Up = T*; _Tp = const T; _Dp = std::default_delete<const
T []>]'|
[..]include\c++\4.7.0\bits\unique_ptr.h|392|error: declared here|
"

This behaviour is in conflict with the standard. Referring to N3290
[unique.ptr.runtime] p1 b2:

"— Pointers to types derived from T are rejected by the constructors, and by
reset."

Further inspection of [unique.ptr.runtime.modifiers] does not reveal any
further constraints that could invalidate the assumption that reset should
accept the pointer to non-const T. This should also not be invalidated by the
constraints on default_delete<T[]>::operator(), because the deleter will always
be called on the internally hold pointer which has the correct type.

In regard to the seemingly difference to the constructor constraints of
[unique.ptr.runtime.ctor] p1 I would like to point to a new LWG issue:

http://cplusplus.github.com/LWG/lwg-active.html#2118

Reply via email to