This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Invalid unique_ptr<T[], D&> test

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 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 test to FAIL.
> Is there any reason I shouldn't simply remove the unique_ptr<T[]>
> parts of

That's no longer necessary, so I'm moving on to non-unique_ptr-related things.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]