Invalid unique_ptr<T[], D&> test

Jonathan Wakely jwakely.gcc@gmail.com
Wed Dec 12 00:09:00 GMT 2012


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.

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));
}

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?



More information about the Libstdc++ mailing list