Topic: defect report: unique_ptr for array does not support cv


Author: "Alf P. Steinbach"<alf.p.steinbach+usenet@gmail.com>
Date: Fri, 16 Dec 2011 11:40:48 -0800 (PST)
Raw View
N3290    20.7.1.3.1 "unique_ptr constructors" [unique.ptr.runtime.ctor]:

   "These constructors behave the same as in the primary template except
that they do not accept pointer types which are convertible to
`pointer`. [/Note:/ One implementation technique is to create private
templated overloads of these members. /   end note/]"

This language excludes even `pointer` itself as type for the actual
argument.

But of more practical concern is that both Visual C++ 10.0 and MinGW g++
4.1.1 reject the code below, where only an implicit cv qualification is
needed, which cv qualification is supported by the non-array version:


<code>
#include<memory>
using namespace std;

struct T {};

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

int main()
{
     unique_ptr<  T const>        p1( bar() );        // OK
     unique_ptr<  T const []>     a1( bar() );        // OK

     unique_ptr<  T const>        p2( foo() );        // OK
     unique_ptr<  T const []>     a2( foo() );        // ? this is line #15
}
</code>


The /intent/ seems to be clearly specified in    20.7.1.3/1 2nd dash:

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

But the following language in    20.7.1.3.1 then rejects far too much...

Proposed new wording of N3290    20.7.1.3.1 "unique_ptr constructors"
[unique.ptr.runtime.ctor]:

   "These constructors behave the same as in the primary template except
that actual argument pointers `p` to types derived from T are rejected
by the constructors. [/Note:/ One implementation technique is to create
private templated overloads of these members. /   end note/]"

This will possibly capture the intent better, and avoid the
inconsistency between the non-array and array versions of unique_ptr, by
using nearly the exact same phrasing as for the paragraph explaining the
intent.


Cheers,

- Alf


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]