This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Invalid unique_ptr<T[], D&> test
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Paolo Carlini <paolo dot carlini at oracle dot com>, Daniel Krügler <daniel dot kruegler at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>, Geoffrey Romer <gromer at google dot com>
- Date: Thu, 20 Dec 2012 21:38:48 +0000
- Subject: Re: Invalid unique_ptr<T[], D&> test
- References: <CAH6eHdRmmNPoc_BDSh69Vniwkw-_DTzoeHQsBFnAPcPbkZR5zg@mail.gmail.com>
On 12 December 2012 00:09, Jonathan Wakely wrote:
> The test added for PR 48635 checks code similar to this:
>
> #include <memory>
> struct D { void operator()(int* p) const { delete[] p; } };
> struct DD : D { };
> DD del;
> std::unique_ptr<int[], DD&> p(new int[1], del);
> std::unique_ptr<int[], D&> pp = std::move(p);
>
> But AFAICT this is invalid and shouldn't compile, the standard doesn't
> define *any* converting constructors for unique_ptr<T[]> whatsoever.
This is now rejected with my new changes, but 48635.cc is still
accepted. I think Geoffrey's reporting a new issue about that.
> We also allow other invalid conversions, e.g. this is invalid (and
> valgrind confirms it has undefined behaviour) but we compile it
> without complaint:
>
> struct A { };
> struct B : A { virtual ~B() { } };
>
> struct D
> {
> template<typename T>
> void operator()(const T* p) const { delete[] p; }
> };
>
> int main()
> {
> std::unique_ptr<B[], D> b(new B[1]);
> std::unique_ptr<A[], D> a(std::move(b));
> }
This is now rejected, which is nice.
> I want to fix this (along with other fixes to unique_ptr<T[]>) but my
> changes cause the 48635.cc test to FAIL.
>
> Is there any reason I shouldn't simply remove the unique_ptr<T[]>
> parts of 48635.cc?
That's no longer necessary, so I'm moving on to non-unique_ptr-related things.