Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #397

defect report: unique_ptr for array does not support cv qualification conversion of actual argument

From "Alf P. Steinbach"<alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.std.c++
Subject defect report: unique_ptr for array does not support cv qualification conversion of actual argument
Date 2011-12-16 11:40 -0800
Organization A noiseless patient Spider
Message-ID <jcfabq$al2$1@dont-email.me> (permalink)

Show all headers | View raw


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                      ]

Back to comp.std.c++ | Previous | Next | Find similar


Thread

defect report: unique_ptr for array does not support cv qualification conversion of actual argument "Alf P. Steinbach"<alf.p.steinbach+usenet@gmail.com> - 2011-12-16 11:40 -0800

csiph-web