+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-#include <memory>
-
-#include "test_macros.h"
-
-int main()
-{
- std::unique_ptr<int> s, s2;
-#if TEST_STD_VER >= 11
- s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
-#else
- s2 = s; // expected-error {{'operator=' is a private member of 'std::__1::unique_ptr}}
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-// test move assignment. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A[]> s1(new A[3]);
- A* p = s1.get();
- assert(A::count == 3);
- std::unique_ptr<A[]> s2(new A[2]);
- assert(A::count == 5);
- s2 = std::move(s1);
- assert(A::count == 3);
- assert(s2.get() == p);
- assert(s1.get() == 0);
- }
- assert(A::count == 0);
- {
- std::unique_ptr<A[], Deleter<A[]> > s1(new A[4], Deleter<A[]>(5));
- A* p = s1.get();
- assert(A::count == 4);
- std::unique_ptr<A[], Deleter<A[]> > s2(new A[5]);
- assert(A::count == 9);
- s2 = std::move(s1);
- assert(s2.get() == p);
- assert(s1.get() == 0);
- assert(A::count == 4);
- assert(s2.get_deleter().state() == 5);
- assert(s1.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- {
- CDeleter<A[]> d1(5);
- std::unique_ptr<A[], CDeleter<A[]>&> s1(new A[6], d1);
- A* p = s1.get();
- assert(A::count == 6);
- CDeleter<A[]> d2(6);
- std::unique_ptr<A[], CDeleter<A[]>&> s2(new A[3], d2);
- assert(A::count == 9);
- s2 = std::move(s1);
- assert(A::count == 6);
- assert(s2.get() == p);
- assert(s1.get() == 0);
- assert(d1.state() == 5);
- assert(d2.state() == 5);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// Can't copy from const lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<A[]> s(new A[3]);
- std::unique_ptr<A[]> s2;
- s2 = s;
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// Can't copy from lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
-public:
-
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p) {delete p;}
-};
-
-int main()
-{
- {
- std::unique_ptr<A, Deleter> s(new A);
- A* p = s.get();
- std::unique_ptr<A, Deleter> s2;
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test move ctor. Can't copy from const lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
-public:
-
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p) {delete p;}
-};
-
-int main()
-{
- {
- const std::unique_ptr<A, Deleter> s(new A);
- A* p = s.get();
- std::unique_ptr<A, Deleter> s2;
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// Can't assign from lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B[]> s(new B);
- A* p = s.get();
- std::unique_ptr<A[]> s2;
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-// Can't assign from lvalue
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- boost::unique_ptr<B[], Deleter<B> > s(new B);
- A* p = s.get();
- boost::unique_ptr<A[], Deleter<A> > s2;
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-// Can't assign from lvalue
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- Deleter<B> db(5);
- boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
- A* p = s.get();
- Deleter<A> da(6);
- boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// Can't assign from const lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- const boost::unique_ptr<B[]> s(new B);
- A* p = s.get();
- boost::unique_ptr<A[]> s2;
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-// Can't assign from const lvalue
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- const boost::unique_ptr<B[], Deleter<B> > s(new B);
- A* p = s.get();
- boost::unique_ptr<A[], Deleter<A> > s2;
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-// Can't assign from const lvalue
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- Deleter<B> db(5);
- const boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
- A* p = s.get();
- Deleter<A> da(6);
- boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- boost::unique_ptr<B[]> s(new B);
- A* p = s.get();
- boost::unique_ptr<A[]> s2(new A);
- assert(A::count == 2);
- s2 = boost::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- boost::unique_ptr<B[], Deleter<B> > s(new B);
- A* p = s.get();
- boost::unique_ptr<A[], Deleter<A> > s2(new A);
- assert(A::count == 2);
- s2 = (boost::move(s));
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-// test converting move assignment with reference deleters
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- Deleter<B> db(5);
- boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
- A* p = s.get();
- Deleter<A> da(6);
- boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
- s2 = boost::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-#include <memory>
-#include <cassert>
-
-// test assignment from null
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A> s2(new A);
- assert(A::count == 1);
- s2 = 0;
- assert(A::count == 0);
- assert(s2.get() == 0);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// The deleter is not called if get() == 0
-
-#include <memory>
-#include <cassert>
-
-#include "test_macros.h"
-
-class Deleter
-{
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(0) {}
-
- int state() const {return state_;}
-
- void operator()(void*) {++state_;}
-};
-
-int main()
-{
- Deleter d;
- assert(d.state() == 0);
- {
- std::unique_ptr<int[], Deleter&> p(nullptr, d);
- assert(p.get() == 0);
- assert(&p.get_deleter() == &d);
- }
-#if defined(_LIBCPP_VERSION)
- {
- // The standard only requires the constructor accept nullptr, but libc++
- // also supports the literal 0.
- std::unique_ptr<int[], Deleter&> p(0, d);
- assert(p.get() == 0);
- assert(&p.get_deleter() == &d);
- }
-#endif
- assert(d.state() == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-#include <memory>
-#include <cassert>
-
-// test assignment from null
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A[]> s2(new A[3]);
- assert(A::count == 3);
- s2 = nullptr;
- assert(A::count == 0);
- assert(s2.get() == 0);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr<T[]>::pointer type
-
-#include <memory>
-#include <type_traits>
-
-struct Deleter
-{
- struct pointer {};
-};
-
-int main()
-{
- {
- typedef std::unique_ptr<int[]> P;
- static_assert((std::is_same<P::pointer, int*>::value), "");
- }
- {
- typedef std::unique_ptr<int[], Deleter> P;
- static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr default ctor
-
-// default unique_ptr ctor should only require default Deleter ctor
-
-#include <memory>
-#include <cassert>
-#include "test_macros.h"
-
-#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11
-_LIBCPP_SAFE_STATIC std::unique_ptr<int[]> global_static_unique_ptr;
-#endif
-
-class Deleter {
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(5) {}
-
- int state() const { return state_; }
-
- void operator()(void*) {}
-};
-
-int main() {
- {
- std::unique_ptr<int[]> p;
- assert(p.get() == 0);
- }
- {
- std::unique_ptr<int[], Deleter> p;
- assert(p.get() == 0);
- assert(p.get_deleter().state() == 5);
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr default ctor
-
-// default unique_ptr ctor should require default Deleter ctor
-
-#include <memory>
-#include "test_macros.h"
-
-class Deleter {
- Deleter() {}
-
-public:
- Deleter(Deleter&) {}
- Deleter& operator=(Deleter&) { return *this; }
-
- void operator()(void*) const {}
-};
-
-int main() {
-#if TEST_STD_VER >= 11
- // expected-error@memory:* {{call to implicitly-deleted default constructor}}
- // expected-note@memory:* {{implicitly deleted because base class 'Deleter' has an inaccessible default constructor}}
-#else
- // expected-error@memory:* {{base class 'Deleter' has private default constructor}}
-#endif
- std::unique_ptr<int[], Deleter> p; // expected-note {{requested here}}
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr default ctor
-
-// default unique_ptr ctor should require non-reference Deleter ctor
-
-#include <memory>
-
-class Deleter
-{
-public:
-
- void operator()(void*) {}
-};
-
-int main()
-{
- std::unique_ptr<int[], Deleter&> p;
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr default ctor
-
-// default unique_ptr ctor should require non-pointer Deleter
-
-#include <memory>
-
-int main()
-{
- std::unique_ptr<int[], void (*)(void*)> p;
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test default unique_ptr<T[]> ctor
-
-// default unique_ptr<T[]> ctor shouldn't require complete type
-
-#include <memory>
-#include <cassert>
-
-struct A;
-
-class Deleter {
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(5) {}
-
- int state() const { return state_; }
-
- void operator()(A* p);
-};
-
-void check(int i);
-
-template <class D = std::default_delete<A> >
-struct B {
- std::unique_ptr<A[], D> a_;
- B();
- ~B();
-
- A* get() const { return a_.get(); }
- D& get_deleter() { return a_.get_deleter(); }
-};
-
-int main() {
- {
- B<> s;
- assert(s.get() == 0);
- }
- check(0);
- {
- B<Deleter> s;
- assert(s.get() == 0);
- assert(s.get_deleter().state() == 5);
- }
- check(0);
-}
-
-struct A {
- static int count;
- A() { ++count; }
- A(const A&) { ++count; }
- ~A() { --count; }
-};
-
-int A::count = 0;
-
-void Deleter::operator()(A* p) { delete p; }
-
-void check(int i) { assert(A::count == i); }
-
-template <class D>
-B<D>::B() {}
-
-template <class D>
-B<D>::~B() {}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-#include <memory>
-#include <cassert>
-
-// test move ctor. Can't copy from lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A[]> s(new A[3]);
- A* p = s.get();
- std::unique_ptr<A[]> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-// test move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A[]> s(new A[3]);
- A* p = s.get();
- std::unique_ptr<A[]> s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 3);
- }
- assert(A::count == 0);
- {
- std::unique_ptr<A[], Deleter<A[]> > s(new A[3], Deleter<A[]>(5));
- A* p = s.get();
- std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 3);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- {
- NCDeleter<A[]> d;
- std::unique_ptr<A[], NCDeleter<A[]>&> s(new A[3], d);
- A* p = s.get();
- std::unique_ptr<A[], NCDeleter<A[]>&> s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 3);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-// test move ctor. Can't copy from const lvalue
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<A[]> s(new A[3]);
- A* p = s.get();
- std::unique_ptr<A[]> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-// test move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-
-std::unique_ptr<A[]>
-source1()
-{
- return std::unique_ptr<A[]>(new A[3]);
-}
-
-void sink1(std::unique_ptr<A[]>)
-{
-}
-
-std::unique_ptr<A[], Deleter<A[]> >
-source2()
-{
- return std::unique_ptr<A[], Deleter<A[]> >(new A[3]);
-}
-
-void sink2(std::unique_ptr<A[], Deleter<A[]> >)
-{
-}
-
-std::unique_ptr<A[], NCDeleter<A[]>&>
-source3()
-{
- static NCDeleter<A[]> d;
- return std::unique_ptr<A[], NCDeleter<A[]>&>(new A[3], d);
-}
-
-void sink3(std::unique_ptr<A[], NCDeleter<A[]>&>)
-{
-}
-
-int main()
-{
- sink1(source1());
- sink2(source2());
- sink3(source3());
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-// test move ctor. Can't copy from lvalue
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
-public:
-
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p) {delete [] p;}
-};
-
-int main()
-{
- {
- std::unique_ptr<A[], Deleter> s(new A[3]);
- A* p = s.get();
- std::unique_ptr<A[], Deleter> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-// test move ctor. Can't copy from const lvalue
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
-public:
-
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p) {delete [] p;}
-};
-
-int main()
-{
- {
- const std::unique_ptr<A[], Deleter> s(new A[3]);
- A* p = s.get();
- std::unique_ptr<A[], Deleter> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B[]> s(new B);
- A* p = s.get();
- std::unique_ptr<A[]> s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B[], Deleter<B[]> > s(new B);
- A* p = s.get();
- std::unique_ptr<A[], Deleter<A[]> > s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A[], CDeleter<A>&> s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// implicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B[]> s(new B);
- A* p = s.get();
- std::unique_ptr<A[]> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Implicit version
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B[], Deleter<B[]> > s(new B);
- A* p = s.get();
- std::unique_ptr<A[], Deleter<A[]> > s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A[], CDeleter<A>&> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<B[]> s(new B);
- A* p = s.get();
- std::unique_ptr<A[]> s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<B[], Deleter<B[]> > s(new B);
- A* p = s.get();
- std::unique_ptr<A[], Deleter<A[]> > s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A[], CDeleter<A>&> s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// implicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<B[]> s(new B);
- A* p = s.get();
- std::unique_ptr<A[]> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Implicit version
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<B[], Deleter<B[]> > s(new B);
- A* p = s.get();
- std::unique_ptr<A[], Deleter<A[]> > s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A[], CDeleter<A>&> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B[]> s(new B);
- A* p = s.get();
- std::unique_ptr<A[]> s2(std::move(s));
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B[], Deleter<B[]> > s(new B);
- A* p = s.get();
- std::unique_ptr<A[], Deleter<A[]> > s2(std::move(s));
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A[], CDeleter<A>&> s2(std::move(s));
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// implicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B[]> s(new B);
- A* p = s.get();
- std::unique_ptr<A[]> s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Implicit version
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B[], Deleter<B[]> > s(new B);
- A* p = s.get();
- std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A[], CDeleter<A>&> s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// unique_ptr(nullptr_t);
-
-#include <memory>
-#include <cassert>
-
-// default unique_ptr ctor should only require default Deleter ctor
-class Deleter
-{
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(void*) {}
-};
-
-int main()
-{
- {
- std::unique_ptr<int[]> p(nullptr);
- assert(p.get() == 0);
- }
- {
- std::unique_ptr<int[], Deleter> p(nullptr);
- assert(p.get() == 0);
- assert(p.get_deleter().state() == 5);
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr<T[]>(pointer) ctor
-
-// unique_ptr<T[]>(pointer) ctor should require default Deleter ctor
-
-#include <memory>
-
-class Deleter
-{
-
- Deleter() {}
-
-public:
-
- Deleter(Deleter&) {}
- Deleter& operator=(Deleter&) {}
-
- void operator()(void*) const {}
-};
-
-int main()
-{
- std::unique_ptr<int[], Deleter> p(new int);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer) ctor
-
-// unique_ptr<T[]>(pointer) ctor should only require default Deleter ctor
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p) {delete [] p;}
-};
-
-int main()
-{
- {
- A* p = new A[3];
- assert(A::count == 3);
- std::unique_ptr<A[]> s(p);
- assert(s.get() == p);
- }
- assert(A::count == 0);
- {
- A* p = new A[3];
- assert(A::count == 3);
- std::unique_ptr<A[], Deleter> s(p);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr<T[]>(pointer) ctor
-
-#include <memory>
-
-// unique_ptr<T[]>(pointer) ctor should require non-reference Deleter ctor
-class Deleter
-{
-public:
-
- void operator()(void*) {}
-};
-
-int main()
-{
- std::unique_ptr<int[], Deleter&> p(new int);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr<T[]>(pointer) ctor
-
-// unique_ptr<T[]>(pointer) ctor shouldn't require complete type
-
-#include <memory>
-#include <cassert>
-
-struct A;
-
-class Deleter
-{
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p);
-};
-
-void check(int i);
-
-template <class D = std::default_delete<A[]> >
-struct B
-{
- std::unique_ptr<A[], D> a_;
- explicit B(A*);
- ~B();
-
- A* get() const {return a_.get();}
- D& get_deleter() {return a_.get_deleter();}
-};
-
-A* get();
-
-int main()
-{
- {
- A* p = get();
- check(3);
- B<> s(p);
- assert(s.get() == p);
- }
- check(0);
- {
- A* p = get();
- check(3);
- B<Deleter> s(p);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- check(0);
-}
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-A* get() {return new A[3];}
-
-void Deleter::operator()(A* p) {delete [] p;}
-
-void check(int i)
-{
- assert(A::count == i);
-}
-
-template <class D>
-B<D>::B(A* a) : a_(a) {}
-
-template <class D>
-B<D>::~B() {}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr<T[]>(pointer) ctor
-
-// unique_ptr<T[]>(pointer) ctor should require non-pointer Deleter
-
-#include <memory>
-
-int main()
-{
- std::unique_ptr<int[], void (*)(void*)> p(new int);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer) ctor
-
-// unique_ptr(pointer) ctor should not work with derived pointers
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-class Deleter
-{
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p) {delete [] p;}
-};
-
-int main()
-{
- {
- B* p = new B[3];
- std::unique_ptr<A[]> s(p);
- }
- {
- B* p = new B[3];
- std::unique_ptr<A[], Deleter> s(p);
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer, deleter) ctor
-
-// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- A* p = new A[3];
- assert(A::count == 3);
- std::unique_ptr<A[], Deleter<A[]> > s(p, Deleter<A[]>());
- assert(s.get() == p);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
-
- { // LWG#2520 says that nullptr is a valid input as well as null
-#ifdef _LIBCPP_VERSION
- std::unique_ptr<A[], Deleter<A[]> > s1(NULL, Deleter<A[]>());
-#endif
- std::unique_ptr<A[], Deleter<A[]> > s2(nullptr, Deleter<A[]>());
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer, deleter) ctor
-
-// unique_ptr(pointer, d) requires CopyConstructible deleter
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
-public:
-
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(A* p) {delete [] p;}
-};
-
-int main()
-{
- {
- A* p = new A[3];
- assert(A::count == 3);
- Deleter d;
- std::unique_ptr<A[], Deleter> s(p, d);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- d.set_state(6);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- {
- Deleter d;
- std::unique_ptr<A[], Deleter> s(nullptr, d);
- assert(s.get() == nullptr);
- assert(s.get_deleter().state() == 5);
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer, deleter) ctor
-
-// unique_ptr<T[], D&>(pointer, d) does not requires CopyConstructible deleter
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
- Deleter(const Deleter&);
- Deleter& operator=(const Deleter&);
-public:
-
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(A* p) {delete [] p;}
-};
-
-int main()
-{
- {
- A* p = new A[3];
- assert(A::count == 3);
- Deleter d;
- std::unique_ptr<A[], Deleter&> s(p, d);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- d.set_state(6);
- assert(s.get_deleter().state() == 6);
- }
- assert(A::count == 0);
- {
- Deleter d;
- std::unique_ptr<A[], Deleter&> s(nullptr, d);
- assert(s.get() == nullptr);
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// XFAIL: c++98, c++03
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer, deleter) ctor
-
-// unique_ptr<T, const D&>(pointer, D()) should not compile
-
-#include <memory>
-
-class Deleter
-{
-public:
- Deleter() {}
- void operator()(int* p) const {delete [] p;}
-};
-
-int main()
-{
- int* p = nullptr;
- std::unique_ptr<int[], const Deleter&> s(p, Deleter()); // expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}}
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer, deleter) ctor
-
-// unique_ptr<T[], const D&>(pointer, d) does not requires CopyConstructible deleter
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
- Deleter(const Deleter&);
- Deleter& operator=(const Deleter&);
-public:
-
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(A* p) const {delete [] p;}
-};
-
-int main()
-{
- {
- A* p = new A[3];
- assert(A::count == 3);
- Deleter d;
- std::unique_ptr<A[], const Deleter&> s(p, d);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- {
- Deleter d;
- std::unique_ptr<A[], const Deleter&> s(nullptr, d);
- assert(s.get() == nullptr);
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer, deleter) ctor
-
-// unique_ptr(pointer, deleter) should not work with derived pointers
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-class Deleter
-{
- int state_;
-
-public:
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p) {delete [] p;}
-};
-
-int main()
-{
- B* p = new B[3];
- std::unique_ptr<A[], Deleter> s(p, Deleter());
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test release
-
-#include <memory>
-#include <cassert>
-
-int main()
-{
- std::unique_ptr<int[]> p(new int[3]);
- int* i = p.get();
- int* j = p.release();
- assert(p.get() == 0);
- assert(i == j);
- delete [] j;
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test reset
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A[]> p(new A[3]);
- assert(A::count == 3);
- A* i = p.get();
- assert(i != nullptr);
- p.reset();
- assert(A::count == 0);
- assert(p.get() == 0);
- }
- assert(A::count == 0);
- {
- std::unique_ptr<A[]> p(new A[4]);
- assert(A::count == 4);
- A* i = p.get();
- assert(i != nullptr);
- p.reset(new A[5]);
- assert(A::count == 5);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test reset
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A[]> p(new A);
- assert(A::count == 1);
- assert(B::count == 0);
- A* i = p.get();
- p.reset(new B);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
- {
- std::unique_ptr<A[]> p(new B);
- assert(A::count == 1);
- assert(B::count == 1);
- A* i = p.get();
- p.reset(new B);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test swap
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- int state_;
- static int count;
- A() : state_(0) {++count;}
- explicit A(int i) : state_(i) {++count;}
- A(const A& a) : state_(a.state_) {++count;}
- A& operator=(const A& a) {state_ = a.state_; return *this;}
- ~A() {--count;}
-
- friend bool operator==(const A& x, const A& y)
- {return x.state_ == y.state_;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- A* p1 = new A[3];
- std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1));
- A* p2 = new A[3];
- std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2));
- assert(s1.get() == p1);
- assert(s1.get_deleter().state() == 1);
- assert(s2.get() == p2);
- assert(s2.get_deleter().state() == 2);
- s1.swap(s2);
- assert(s1.get() == p2);
- assert(s1.get_deleter().state() == 2);
- assert(s2.get() == p1);
- assert(s2.get_deleter().state() == 1);
- assert(A::count == 6);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test op*()
-
-#include <memory>
-#include <cassert>
-
-int main()
-{
- std::unique_ptr<int[]> p(new int(3));
- assert(*p == 3);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test get_deleter()
-
-#include <memory>
-#include <cassert>
-#include "test_macros.h"
-
-struct Deleter {
- Deleter() {}
-
- void operator()(void*) const {}
-
- int test() { return 5; }
- int test() const { return 6; }
-};
-
-int main() {
- {
- std::unique_ptr<int[], Deleter> p;
- assert(p.get_deleter().test() == 5);
- }
- {
- const std::unique_ptr<int[], Deleter> p;
- assert(p.get_deleter().test() == 6);
- }
- {
- typedef std::unique_ptr<int[], const Deleter&> UPtr;
- const Deleter d;
- UPtr p(nullptr, d);
- const UPtr& cp = p;
- ASSERT_SAME_TYPE(decltype(p.get_deleter()), const Deleter&);
- ASSERT_SAME_TYPE(decltype(cp.get_deleter()), const Deleter&);
- assert(p.get_deleter().test() == 6);
- assert(cp.get_deleter().test() == 6);
- }
- {
- typedef std::unique_ptr<int[], Deleter&> UPtr;
- Deleter d;
- UPtr p(nullptr, d);
- const UPtr& cp = p;
- ASSERT_SAME_TYPE(decltype(p.get_deleter()), Deleter&);
- ASSERT_SAME_TYPE(decltype(cp.get_deleter()), Deleter&);
- assert(p.get_deleter().test() == 5);
- assert(cp.get_deleter().test() == 5);
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test op[](size_t)
-
-#include <memory>
-#include <cassert>
-
-class A
-{
- int state_;
- static int next_;
-public:
- A() : state_(++next_) {}
- int get() const {return state_;}
-
- friend bool operator==(const A& x, int y)
- {return x.state_ == y;}
-
- A& operator=(int i) {state_ = i; return *this;}
-};
-
-int A::next_ = 0;
-
-int main()
-{
- std::unique_ptr<A[]> p(new A[3]);
- assert(p[0] == 1);
- assert(p[1] == 2);
- assert(p[2] == 3);
- p[0] = 3;
- p[1] = 2;
- p[2] = 1;
- assert(p[0] == 3);
- assert(p[1] == 2);
- assert(p[2] == 1);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr::pointer type
-
-#include <memory>
-#include <type_traits>
-
-#include "test_macros.h"
-
-struct Deleter
-{
- struct pointer {};
-};
-
-struct D2 {
-private:
- typedef void pointer;
-};
-
-struct D3 {
- static long pointer;
-};
-
-int main()
-{
- {
- typedef std::unique_ptr<int> P;
- static_assert((std::is_same<P::pointer, int*>::value), "");
- }
- {
- typedef std::unique_ptr<int, Deleter> P;
- static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
- }
-#if TEST_STD_VER >= 11
- {
- typedef std::unique_ptr<int, D2> P;
- static_assert(std::is_same<P::pointer, int*>::value, "");
- }
- {
- typedef std::unique_ptr<int, D3> P;
- static_assert(std::is_same<P::pointer, int*>::value, "");
- }
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-#include <memory>
-
-#include "test_macros.h"
-
-// Can't copy from lvalue
-int main()
-{
- std::unique_ptr<int> s, s2;
-#if TEST_STD_VER >= 11
- s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
-#else
- s2 = s; // expected-error {{'operator=' is a private member}}
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-// test move assignment. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A> s1(new A);
- A* p = s1.get();
- std::unique_ptr<A> s2(new A);
- assert(A::count == 2);
- s2 = std::move(s1);
- assert(A::count == 1);
- assert(s2.get() == p);
- assert(s1.get() == 0);
- }
- assert(A::count == 0);
- {
- std::unique_ptr<A, Deleter<A> > s1(new A, Deleter<A>(5));
- A* p = s1.get();
- std::unique_ptr<A, Deleter<A> > s2(new A);
- assert(A::count == 2);
- s2 = std::move(s1);
- assert(s2.get() == p);
- assert(s1.get() == 0);
- assert(A::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s1.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- {
- CDeleter<A> d1(5);
- std::unique_ptr<A, CDeleter<A>&> s1(new A, d1);
- A* p = s1.get();
- CDeleter<A> d2(6);
- std::unique_ptr<A, CDeleter<A>&> s2(new A, d2);
- s2 = std::move(s1);
- assert(s2.get() == p);
- assert(s1.get() == 0);
- assert(A::count == 1);
- assert(d1.state() == 5);
- assert(d2.state() == 5);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-#include <memory>
-
-#include "test_macros.h"
-
-// Can't copy from const lvalue
-
-int main()
-{
- const std::unique_ptr<int> s(new int);
- std::unique_ptr<int> s2;
-#if TEST_STD_VER >= 11
- s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
-#else
- // NOTE: The error says "constructor" because the assignment operator takes
- // 's' by value and attempts to copy construct it.
- s2 = s; // expected-error {{no matching constructor for initialization}}
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-#include <memory>
-
-#include "test_macros.h"
-
-struct Deleter {
- void operator()(int* p) {delete p;}
-};
-
-// Can't copy from lvalue
-int main()
-{
- std::unique_ptr<int, Deleter> s, s2;
-#if TEST_STD_VER >= 11
- s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
-#else
- s2 = s; // expected-error {{'operator=' is a private member}}
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move assignment
-
-#include <memory>
-
-#include "test_macros.h"
-
-struct Deleter {
- void operator()(int* p) {delete p;}
-};
-
-// Can't copy from a const lvalue
-int main()
-{
- const std::unique_ptr<int, Deleter> s(new int);
- std::unique_ptr<int, Deleter> s2;
-#if TEST_STD_VER >= 11
- s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
-#else
- // NOTE: The error says "constructor" because the assignment operator takes
- // 's' by value and attempts to copy construct it.
- s2 = s; // expected-error {{no matching constructor for initialization}}
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-
-template <class APtr, class BPtr>
-void testAssign(APtr& aptr, BPtr& bptr) {
- A* p = bptr.get();
- assert(A::count == 2);
- aptr = std::move(bptr);
- assert(aptr.get() == p);
- assert(bptr.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
-}
-
-template <class LHS, class RHS>
-void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) {
- assert(lhs.get_deleter().state() == LHSState);
- assert(rhs.get_deleter().state() == RHSState);
-}
-
-int main()
-{
- {
- std::unique_ptr<B> bptr(new B);
- std::unique_ptr<A> aptr(new A);
- testAssign(aptr, bptr);
- }
- assert(A::count == 0);
- assert(B::count == 0);
- {
- Deleter<B> del(42);
- std::unique_ptr<B, Deleter<B> > bptr(new B, std::move(del));
- std::unique_ptr<A, Deleter<A> > aptr(new A);
- testAssign(aptr, bptr);
- checkDeleter(aptr, bptr, 42, 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
- {
- CDeleter<A> adel(6);
- CDeleter<B> bdel(42);
- std::unique_ptr<B, CDeleter<B>&> bptr(new B, bdel);
- std::unique_ptr<A, CDeleter<A>&> aptr(new A, adel);
- testAssign(aptr, bptr);
- checkDeleter(aptr, bptr, 42, 42);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-#include <memory>
-
-#include "test_macros.h"
-
-struct A
-{
- A() {}
- virtual ~A() {}
-};
-
-struct B : public A
-{
-};
-
-// Can't assign from lvalue
-int main()
-{
- std::unique_ptr<B> s;
- std::unique_ptr<A> s2;
-#if TEST_STD_VER >= 11
- s2 = s; // expected-error {{no viable overloaded '='}}
-#else
- // NOTE: The move-semantic emulation creates an ambiguous overload set
- // so that assignment from an lvalue does not compile
- s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}}
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-#include <memory>
-
-#include "test_macros.h"
-#include "deleter_types.h"
-
-struct A
-{
- A() {}
- virtual ~A() {}
-};
-
-struct B : public A
-{
-};
-
-// Can't assign from lvalue
-int main()
-{
- std::unique_ptr<B, Deleter<B> > s;
- std::unique_ptr<A, Deleter<A> > s2;
-#if TEST_STD_VER >= 11
- s2 = s; // expected-error {{no viable overloaded '='}}
-#else
- // NOTE: The move-semantic emulation creates an ambiguous overload set
- // so that assignment from an lvalue does not compile
- s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}}
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-// Can't assign from lvalue
-
-#include <memory>
-
-#include "test_macros.h"
-#include "deleter_types.h"
-
-struct A
-{
- A() {}
- virtual ~A() {}
-};
-
-struct B : public A
-{
-};
-
-// Can't assign from lvalue
-int main()
-{
- Deleter<B> db;
- std::unique_ptr<B, Deleter<B>& > s(new B, db);
- Deleter<A> da;
- std::unique_ptr<A, Deleter<A> &> s2(new A, da);
-#if TEST_STD_VER >= 11
- s2 = s; // expected-error {{no viable overloaded '='}}
-#else
- // NOTE: The move-semantic emulation creates an ambiguous overload set
- // so that assignment from an lvalue does not compile
- s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}}
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-#include <memory>
-
-#include "test_macros.h"
-#include "deleter_types.h"
-
-struct A
-{
- A() {}
- virtual ~A() {}
-};
-
-struct B : public A
-{
-};
-
-// Can't assign from lvalue
-int main()
-{
- const std::unique_ptr<B> s(new B);
- std::unique_ptr<A> s2;
-#if TEST_STD_VER >= 11
- s2 = s; // expected-error {{no viable overloaded '='}}
-#else
- // NOTE: The error says "constructor" because the assignment operator takes
- // 's' by value and attempts to copy construct it.
- s2 = s; // expected-error {{no matching constructor for initialization}}
-#endif
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-// Can't assign from const lvalue
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<B, Deleter<B> > s(new B);
- A* p = s.get();
- std::unique_ptr<A, Deleter<A> > s2;
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-// Can't assign from const lvalue
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- Deleter<B> db(5);
- const std::unique_ptr<B, Deleter<B>&> s(new B, db);
- A* p = s.get();
- Deleter<A> da(6);
- std::unique_ptr<A, Deleter<A>&> s2(new A, da);
- s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move assignment
-
-// Do not convert from an array unique_ptr
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-struct A
-{
-};
-
-struct Deleter
-{
- void operator()(void*) {}
-};
-
-int main()
-{
- std::unique_ptr<A[], Deleter> s;
- std::unique_ptr<A, Deleter> s2;
- s2 = std::move(s); // expected-error {{no viable overloaded '='}}
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer) ctor
-
-#include <memory>
-#include <cassert>
-
-// template <class U> explicit unique_ptr(auto_ptr<U>&);
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
-// : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- B* p = new B;
- std::auto_ptr<B> ap(p);
- std::unique_ptr<A> up(ap);
- assert(up.get() == p);
- assert(ap.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
- {
- B* p = new B;
- std::auto_ptr<B> ap(p);
- std::unique_ptr<A> up;
- up = ap;
- assert(up.get() == p);
- assert(ap.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer) ctor
-
-#include <memory>
-#include <cassert>
-
-// template <class U> explicit unique_ptr(auto_ptr<U>&);
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-struct Deleter
-{
- template <class T>
- void operator()(T*) {}
-};
-
-int main()
-{
- {
- B* p = new B;
- std::auto_ptr<B> ap(p);
- std::unique_ptr<A, Deleter> up(ap);
- assert(up.get() == p);
- assert(ap.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-//=============================================================================
-// TESTING std::unique_ptr::unique_ptr()
-//
-// Concerns:
-// 1 The default constructor works for any default constructible deleter types.
-// 2 The stored type 'T' is allowed to be incomplete.
-//
-// Plan
-// 1 Default construct unique_ptr's with various deleter types (C-1)
-// 2 Default construct a unique_ptr with an incomplete element_type and
-// various deleter types (C-1,2)
-
-#include <memory>
-#include <cassert>
-#include "test_macros.h"
-
-#include "deleter_types.h"
-
-#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11
-_LIBCPP_SAFE_STATIC std::unique_ptr<int> global_static_unique_ptr;
-#endif
-
-struct IncompleteT;
-
-void checkNumIncompleteTypeAlive(int i);
-
-template <class Del = std::default_delete<IncompleteT> >
-struct StoresIncomplete {
- std::unique_ptr<IncompleteT, Del> m_ptr;
- StoresIncomplete() {}
- ~StoresIncomplete();
-
- IncompleteT* get() const { return m_ptr.get(); }
- Del& get_deleter() { return m_ptr.get_deleter(); }
-};
-
-int main()
-{
- {
- std::unique_ptr<int> p;
- assert(p.get() == 0);
- }
- {
- std::unique_ptr<int, NCDeleter<int> > p;
- assert(p.get() == 0);
- assert(p.get_deleter().state() == 0);
- p.get_deleter().set_state(5);
- assert(p.get_deleter().state() == 5);
- }
- {
- StoresIncomplete<> s;
- assert(s.get() == 0);
- checkNumIncompleteTypeAlive(0);
- }
- checkNumIncompleteTypeAlive(0);
- {
- StoresIncomplete< Deleter<IncompleteT> > s;
- assert(s.get() == 0);
- assert(s.get_deleter().state() == 0);
- checkNumIncompleteTypeAlive(0);
- }
- checkNumIncompleteTypeAlive(0);
-}
-
-struct IncompleteT {
- static int count;
- IncompleteT() { ++count; }
- ~IncompleteT() {--count; }
-};
-
-int IncompleteT::count = 0;
-
-void checkNumIncompleteTypeAlive(int i) {
- assert(IncompleteT::count == i);
-}
-
-template <class Del>
-StoresIncomplete<Del>::~StoresIncomplete() { }
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr default ctor
-
-#include <memory>
-
-// default unique_ptr ctor should require default Deleter ctor
-class Deleter
-{
-
- Deleter() {}
-
-public:
-
- Deleter(Deleter&) {}
- Deleter& operator=(Deleter&) {}
-
- void operator()(void*) const {}
-};
-
-int main()
-{
- std::unique_ptr<int, Deleter> p;
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr default ctor
-
-#include <memory>
-
-// default unique_ptr ctor should require non-reference Deleter ctor
-class Deleter
-{
-public:
-
- void operator()(void*) {}
-};
-
-int main()
-{
- std::unique_ptr<int, Deleter&> p;
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr default ctor
-
-#include <memory>
-
-// default unique_ptr ctor should require non-pointer Deleter
-
-int main()
-{
- std::unique_ptr<int, void (*)(void*)> p;
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-//=============================================================================
-// TESTING unique_ptr(unique_ptr&&)
-//
-// Concerns
-// 1 The moved from pointer is empty and the new pointer stores the old value.
-// 2 The only requirement on the deleter is that it is MoveConstructible
-// or a reference.
-// 3 The constructor works for explicitly moved values (ie std::move(x))
-// 4 The constructor works for true temporaries (ie a return value)
-//
-// Plan
-// 1 Explicitly construct unique_ptr<T, D> for various deleter types 'D'.
-// check that the value and deleter have been properly moved. (C-1,2,3)
-//
-// 2 Use the expression 'sink(source())' to move construct a unique_ptr<T, D>
-// from a temporary. 'source' should return the unique_ptr by value and
-// 'sink' should accept the unique_ptr by value. (C-1,2,4)
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-template <class Expect>
-void sinkFunction(Expect)
-{
-}
-
-typedef std::unique_ptr<A> APtrSource1;
-typedef std::unique_ptr<A, Deleter<A> > APtrSource2;
-typedef std::unique_ptr<A, NCDeleter<A>& > APtrSource3;
-
-APtrSource1 source1() {
- return APtrSource1 (new A);
-}
-
-void sink1(APtrSource1 p) {
- assert(p.get() != nullptr);
-}
-
-APtrSource2 source2() {
- return APtrSource2(new A, Deleter<A>(5));
-}
-
-void sink2(APtrSource2 p) {
- assert(p.get() != nullptr);
- assert(p.get_deleter().state() == 5);
-}
-
-APtrSource3 source3() {
- static NCDeleter<A> d(5);
- return APtrSource3(new A, d);
-}
-
-void sink3(APtrSource3 p) {
- assert(p.get() != nullptr);
- assert(p.get_deleter().state() == 5);
- assert(&p.get_deleter() == &source3().get_deleter());
-}
-
-int main()
-{
- {
- typedef std::unique_ptr<A> APtr;
- APtr s(new A);
- A* p = s.get();
- APtr s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
- {
- typedef Deleter<A> MoveDel;
- typedef std::unique_ptr<A, MoveDel> APtr;
- MoveDel d(5);
- APtr s(new A, std::move(d));
- assert(d.state() == 0);
- assert(s.get_deleter().state() == 5);
- A* p = s.get();
- APtr s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- {
- typedef NCDeleter<A> NonCopyDel;
- typedef std::unique_ptr<A, NonCopyDel&> APtr;
-
- NonCopyDel d;
- APtr s(new A, d);
- A* p = s.get();
- APtr s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- {
- sink1(source1());
- assert(A::count == 0);
- sink2(source2());
- assert(A::count == 0);
- sink3(source3());
- assert(A::count == 0);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-#include <memory>
-#include <cassert>
-
-// test move ctor. Can't copy from lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A> s(new A);
- A* p = s.get();
- std::unique_ptr<A> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-#include <memory>
-#include <cassert>
-
-// test move ctor. Can't copy from const lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<A> s(new A);
- A* p = s.get();
- std::unique_ptr<A> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-#include <memory>
-#include <cassert>
-
-// test move ctor. Can't copy from lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
-public:
-
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p) {delete p;}
-};
-
-int main()
-{
- {
- std::unique_ptr<A, Deleter> s(new A);
- A* p = s.get();
- std::unique_ptr<A, Deleter> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr move ctor
-
-#include <memory>
-#include <cassert>
-
-// test move ctor. Can't copy from const lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-class Deleter
-{
- int state_;
-
-public:
-
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p) {delete p;}
-};
-
-int main()
-{
- {
- const std::unique_ptr<A, Deleter> s(new A);
- A* p = s.get();
- std::unique_ptr<A, Deleter> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// NOTE: unique_ptr does not provide converting constructors in c++03
-// XFAIL: c++98, c++03
-
-
-
-#include <memory>
-#include <type_traits>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-
-template <class LHS, class RHS>
-void checkReferenceDeleter(LHS& lhs, RHS& rhs) {
- typedef typename LHS::deleter_type NewDel;
- static_assert(std::is_reference<NewDel>::value, "");
- rhs.get_deleter().set_state(42);
- assert(rhs.get_deleter().state() == 42);
- assert(lhs.get_deleter().state() == 42);
- lhs.get_deleter().set_state(99);
- assert(lhs.get_deleter().state() == 99);
- assert(rhs.get_deleter().state() == 99);
-}
-
-template <class LHS, class RHS>
-void checkDeleter(LHS& lhs, RHS& rhs, int LHSVal, int RHSVal) {
- assert(lhs.get_deleter().state() == LHSVal);
- assert(rhs.get_deleter().state() == RHSVal);
-}
-
-template <class LHS, class RHS>
-void checkCtor(LHS& lhs, RHS& rhs, A* RHSVal) {
- assert(lhs.get() == RHSVal);
- assert(rhs.get() == nullptr);
- assert(A::count == 1);
- assert(B::count == 1);
-}
-
-void checkNoneAlive() {
- assert(A::count == 0);
- assert(B::count == 0);
-}
-
-int main()
-{
- {
- typedef std::unique_ptr<A> APtr;
- typedef std::unique_ptr<B> BPtr;
- { // explicit
- BPtr b(new B);
- A* p = b.get();
- APtr a(std::move(b));
- checkCtor(a, b, p);
- }
- checkNoneAlive();
- { // implicit
- BPtr b(new B);
- A* p = b.get();
- APtr a = std::move(b);
- checkCtor(a, b, p);
- }
- checkNoneAlive();
- }
- { // test with moveable deleters
- typedef std::unique_ptr<A, Deleter<A> > APtr;
- typedef std::unique_ptr<B, Deleter<B> > BPtr;
- {
- Deleter<B> del(5);
- BPtr b(new B, std::move(del));
- A* p = b.get();
- APtr a(std::move(b));
- checkCtor(a, b, p);
- checkDeleter(a, b, 5, 0);
- }
- checkNoneAlive();
- {
- Deleter<B> del(5);
- BPtr b(new B, std::move(del));
- A* p = b.get();
- APtr a = std::move(b);
- checkCtor(a, b, p);
- checkDeleter(a, b, 5, 0);
- }
- checkNoneAlive();
-
- }
- { // test with reference deleters
- typedef std::unique_ptr<A, NCDeleter<A>& > APtr;
- typedef std::unique_ptr<B, NCDeleter<A>& > BPtr;
- NCDeleter<A> del(5);
- {
- BPtr b(new B, del);
- A* p = b.get();
- APtr a(std::move(b));
- checkCtor(a, b, p);
- checkReferenceDeleter(a, b);
- }
- checkNoneAlive();
- {
- BPtr b(new B, del);
- A* p = b.get();
- APtr a = std::move(b);
- checkCtor(a, b, p);
- checkReferenceDeleter(a, b);
- }
- checkNoneAlive();
- }
- {
- typedef std::unique_ptr<A, CDeleter<A> > APtr;
- typedef std::unique_ptr<B, CDeleter<B>& > BPtr;
- CDeleter<B> del(5);
- {
- BPtr b(new B, del);
- A* p = b.get();
- APtr a(std::move(b));
- checkCtor(a, b, p);
- checkDeleter(a, b, 5, 5);
- }
- checkNoneAlive();
- {
- BPtr b(new B, del);
- A* p = b.get();
- APtr a = std::move(b);
- checkCtor(a, b, p);
- checkDeleter(a, b, 5, 5);
- }
- checkNoneAlive();
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// Can't construct from lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B> s(new B);
- A* p = s.get();
- std::unique_ptr<A> s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B, Deleter<B> > s(new B);
- A* p = s.get();
- std::unique_ptr<A, Deleter<A> > s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- std::unique_ptr<B, CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A, CDeleter<A>&> s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// implicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<B> s(new B);
- A* p = s.get();
- std::unique_ptr<A> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "deleter_types.h"
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Implicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- std::unique_ptr<B, Deleter<B> > s(new B);
- std::unique_ptr<A, Deleter<A> > s2 = s;
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- std::unique_ptr<B, CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A, CDeleter<A>&> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<B> s(new B);
- A* p = s.get();
- std::unique_ptr<A> s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++98, c++03
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class Deleter
-{
- int state_;
- Deleter(const Deleter&);
- Deleter& operator=(const Deleter&);
-
-public:
- Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
- Deleter& operator=(Deleter&& r)
- {
- state_ = r.state_;
- r.state_ = 0;
- return *this;
- }
-
- Deleter() : state_(5) {}
-
- template <class U>
- Deleter(Deleter<U>&& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
- : state_(d.state()) {d.set_state(0);}
-
-private:
- template <class U>
- Deleter(const Deleter<U>& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
-
-public:
- int state() const {return state_;}
- void set_state(int i) {state_ = i;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- const std::unique_ptr<B, Deleter<B> > s;
- std::unique_ptr<A, Deleter<A> > s2(s); // expected-error {{no matching constructor}}
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- const std::unique_ptr<B, CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A, CDeleter<A>&> s2(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// implicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
- const std::unique_ptr<B> s(new B);
- A* p = s.get();
- std::unique_ptr<A> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++98, c++03
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Implicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class Deleter
-{
- int state_;
-
- Deleter(const Deleter&);
- Deleter& operator=(const Deleter&);
-public:
- Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
- Deleter& operator=(Deleter&& r)
- {
- state_ = r.state_;
- r.state_ = 0;
- return *this;
- }
-
- Deleter() : state_(5) {}
-
- template <class U>
- Deleter(Deleter<U>&& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
- : state_(d.state()) {d.set_state(0);}
-
-private:
- template <class U>
- Deleter(const Deleter<U>& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
-
-public:
- int state() const {return state_;}
- void set_state(int i) {state_ = i;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- const std::unique_ptr<B, Deleter<B> > s;
- std::unique_ptr<A, Deleter<A> > s2 = s; // expected-error {{no viable conversion}}
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-// test converting move ctor. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-// Explicit version
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-template <class T>
-class CDeleter
-{
- int state_;
-
- CDeleter(CDeleter&);
- CDeleter& operator=(CDeleter&);
-public:
-
- CDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- CDeleter<A> d;
- const std::unique_ptr<B, CDeleter<A>&> s(new B, d);
- A* p = s.get();
- std::unique_ptr<A, CDeleter<A>&> s2 = s;
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- d.set_state(6);
- assert(s2.get_deleter().state() == d.state());
- assert(s.get_deleter().state() == d.state());
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr converting move ctor
-
-// Do not convert from an array unique_ptr
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-struct A
-{
-};
-
-struct Deleter
-{
- void operator()(void*) {}
-};
-
-int main()
-{
- std::unique_ptr<A[], Deleter> s;
- std::unique_ptr<A, Deleter> s2(std::move(s));
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// unique_ptr(nullptr_t);
-
-#include <memory>
-#include <cassert>
-
-// default unique_ptr ctor should only require default Deleter ctor
-class Deleter
-{
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(void*) {}
-};
-
-int main()
-{
- {
- std::unique_ptr<int> p(nullptr);
- assert(p.get() == 0);
- }
- {
- std::unique_ptr<int, Deleter> p(nullptr);
- assert(p.get() == 0);
- assert(p.get_deleter().state() == 5);
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-//=============================================================================
-// TESTING std::unique_ptr::unique_ptr()
-//
-// Concerns:
-// 1 The pointer constructor works for any default constructible deleter types.
-// 2 The pointer constructor accepts pointers to derived types.
-// 2 The stored type 'T' is allowed to be incomplete.
-//
-// Plan
-// 1 Construct unique_ptr<T, D>'s with a pointer to 'T' and various deleter
-// types (C-1)
-// 2 Construct unique_ptr<T, D>'s with a pointer to 'D' and various deleter
-// types where 'D' is derived from 'T'. (C-1,2)
-// 3 Construct a unique_ptr<T, D> with a pointer to 'T' and various deleter
-// types where 'T' is an incomplete type (C-1,3)
-
-// Test unique_ptr(pointer) ctor
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-// unique_ptr(pointer) ctor should only require default Deleter ctor
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-
-struct IncompleteT;
-
-IncompleteT* getIncomplete();
-void checkNumIncompleteTypeAlive(int i);
-
-template <class Del = std::default_delete<IncompleteT> >
-struct StoresIncomplete {
- std::unique_ptr<IncompleteT, Del> m_ptr;
- StoresIncomplete() {}
- explicit StoresIncomplete(IncompleteT* ptr) : m_ptr(ptr) {}
- ~StoresIncomplete();
-
- IncompleteT* get() const { return m_ptr.get(); }
- Del& get_deleter() { return m_ptr.get_deleter(); }
-};
-
-void test_pointer()
-{
- {
- A* p = new A;
- assert(A::count == 1);
- std::unique_ptr<A> s(p);
- assert(s.get() == p);
- }
- assert(A::count == 0);
- {
- A* p = new A;
- assert(A::count == 1);
- std::unique_ptr<A, NCDeleter<A> > s(p);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
-}
-
-void test_derived()
-{
- {
- B* p = new B;
- assert(A::count == 1);
- assert(B::count == 1);
- std::unique_ptr<A> s(p);
- assert(s.get() == p);
- }
- assert(A::count == 0);
- assert(B::count == 0);
- {
- B* p = new B;
- assert(A::count == 1);
- assert(B::count == 1);
- std::unique_ptr<A, NCDeleter<A> > s(p);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
-
-void test_incomplete()
-{
- {
- IncompleteT* p = getIncomplete();
- checkNumIncompleteTypeAlive(1);
- StoresIncomplete<> s(p);
- assert(s.get() == p);
- }
- checkNumIncompleteTypeAlive(0);
- {
- IncompleteT* p = getIncomplete();
- checkNumIncompleteTypeAlive(1);
- StoresIncomplete< NCDeleter<IncompleteT> > s(p);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 0);
- }
- checkNumIncompleteTypeAlive(0);
-}
-
-struct IncompleteT {
- static int count;
- IncompleteT() { ++count; }
- ~IncompleteT() {--count; }
-};
-
-int IncompleteT::count = 0;
-
-IncompleteT* getIncomplete() {
- return new IncompleteT;
-}
-
-void checkNumIncompleteTypeAlive(int i) {
- assert(IncompleteT::count == i);
-}
-
-template <class Del>
-StoresIncomplete<Del>::~StoresIncomplete() { }
-
-int main()
-{
- test_pointer();
- test_derived();
- test_incomplete();
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer) ctor
-
-#include <memory>
-
-// unique_ptr(pointer) ctor should require default Deleter ctor
-class Deleter
-{
-
- Deleter() {}
-
-public:
-
- Deleter(Deleter&) {}
- Deleter& operator=(Deleter&) {}
-
- void operator()(void*) const {}
-};
-
-int main()
-{
- std::unique_ptr<int, Deleter> p(new int);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer) ctor
-
-#include <memory>
-
-// unique_ptr(pointer) ctor should require non-reference Deleter ctor
-class Deleter
-{
-public:
-
- void operator()(void*) {}
-};
-
-int main()
-{
- std::unique_ptr<int, Deleter&> p(new int);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr(pointer) ctor
-
-#include <memory>
-
-// unique_ptr(pointer) ctor should require non-pointer Deleter
-
-int main()
-{
- std::unique_ptr<int, void (*)(void*)> p(new int);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-//=============================================================================
-// TESTING unique_ptr(pointer, deleter)
-//
-// Concerns:
-// 1 unique_ptr(pointer, deleter&&) only requires a MoveConstructible deleter.
-// 2 unique_ptr(pointer, deleter&) requires a CopyConstructible deleter.
-// 3 unique_ptr<T, D&>(pointer, deleter) does not require a CopyConstructible deleter.
-// 4 unique_ptr<T, D const&>(pointer, deleter) does not require a CopyConstructible deleter.
-// 5 unique_ptr(pointer, deleter) should work for derived pointers.
-// 6 unique_ptr(pointer, deleter) should work with function pointers.
-// 7 unique_ptr<void> should work.
-
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
-
-int A::count = 0;
-
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-bool my_free_called = false;
-
-void my_free(void*) {
- my_free_called = true;
-}
-
-int main()
-{
- { // MoveConstructible deleter (C-1)
- A* p = new A;
- assert(A::count == 1);
- std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>(5));
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- { // CopyConstructible deleter (C-2)
- A* p = new A;
- assert(A::count == 1);
- CopyDeleter<A> d(5);
- std::unique_ptr<A, CopyDeleter<A> > s(p, d);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- d.set_state(6);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- { // Reference deleter (C-3)
- A* p = new A;
- assert(A::count == 1);
- NCDeleter<A> d(5);
- std::unique_ptr<A, NCDeleter<A>&> s(p, d);
- assert(s.get() == p);
- assert(&s.get_deleter() == &d);
- assert(s.get_deleter().state() == 5);
- d.set_state(6);
- assert(s.get_deleter().state() == 6);
- }
- assert(A::count == 0);
- { // Const Reference deleter (C-4)
- A* p = new A;
- assert(A::count == 1);
- NCConstDeleter<A> d(5);
- std::unique_ptr<A, NCConstDeleter<A> const&> s(p, d);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- assert(&s.get_deleter() == &d);
- }
- assert(A::count == 0);
- { // Derived pointers (C-5)
- B* p = new B;
- assert(A::count == 1);
- assert(B::count == 1);
- std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>(5));
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- assert(B::count == 0);
- { // Void and function pointers (C-6,7)
- {
- int i = 0;
- std::unique_ptr<void, void(*)(void*)> s(&i, my_free);
- assert(s.get() == &i);
- assert(s.get_deleter() == my_free);
- assert(!my_free_called);
- }
- assert(my_free_called);
- }
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test release
-
-#include <memory>
-#include <cassert>
-
-int main()
-{
- std::unique_ptr<int> p(new int(3));
- int* i = p.get();
- int* j = p.release();
- assert(p.get() == 0);
- assert(i == j);
- delete j;
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test reset
-
-#include <memory>
-#include <cassert>
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A> p(new A);
- assert(A::count == 1);
- A* i = p.get();
- assert(i != nullptr);
- p.reset();
- assert(A::count == 0);
- assert(p.get() == 0);
- }
- assert(A::count == 0);
- {
- std::unique_ptr<A> p(new A);
- assert(A::count == 1);
- A* i = p.get();
- assert(i != nullptr);
- p.reset(new A);
- assert(A::count == 1);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test swap
-
-#include <memory>
-#include <cassert>
-
-#include "deleter_types.h"
-
-struct A
-{
- int state_;
- static int count;
- explicit A(int i) : state_(i) {++count;}
- A(const A& a) : state_(a.state_) {++count;}
- A& operator=(const A& a) {state_ = a.state_; return *this;}
- ~A() {--count;}
-
- friend bool operator==(const A& x, const A& y)
- {return x.state_ == y.state_;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- A* p1 = new A(1);
- std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1));
- A* p2 = new A(2);
- std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2));
- assert(s1.get() == p1);
- assert(*s1 == A(1));
- assert(s1.get_deleter().state() == 1);
- assert(s2.get() == p2);
- assert(*s2 == A(2));
- assert(s2.get_deleter().state() == 2);
- s1.swap(s2);
- assert(s1.get() == p2);
- assert(*s1 == A(2));
- assert(s1.get_deleter().state() == 2);
- assert(s2.get() == p1);
- assert(*s2 == A(1));
- assert(s2.get_deleter().state() == 1);
- assert(A::count == 2);
- }
- assert(A::count == 0);
-}
+++ /dev/null
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// test get
-
-#include <memory>
-#include <cassert>
-
-int main()
-{
- int* p = new int;
- std::unique_ptr<int> s(p);
- assert(s.get() == p);
-}
--- /dev/null
+Test Naming and Directory Structure
+===================================
+
+The directory structure for the unique_ptr class templates differs from the
+normal test directory naming conventions (e.g. matching the stable name in the standard).
+
+Instead of having a [unique.ptr.single] and [unique.ptr.runtime] directory,
+each containing their own tests, a single directory, "unique.ptr.class",
+contains both sets of tests.
+
+This allows the common behavior of the two unique_ptr specializations to be
+tested in the same place without duplication.
+
+Tests specific to [unique.ptr.single] have the suffix ".single.pass.cpp"
+and those specific to [unique.ptr.runtime] are named "*.runtime.pass.cpp".
+Tests for both specializations are named normally.
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// Test unique_ptr::pointer type
+
+#include <memory>
+#include <type_traits>
+
+#include "test_macros.h"
+
+struct Deleter {
+ struct pointer {};
+};
+
+struct D2 {
+private:
+ typedef void pointer;
+};
+
+struct D3 {
+ static long pointer;
+};
+
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, int[], int>::type VT;
+ {
+ typedef std::unique_ptr<VT> P;
+ static_assert((std::is_same<typename P::pointer, int*>::value), "");
+ }
+ {
+ typedef std::unique_ptr<VT, Deleter> P;
+ static_assert((std::is_same<typename P::pointer, Deleter::pointer>::value),
+ "");
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef std::unique_ptr<VT, D2> P;
+ static_assert(std::is_same<typename P::pointer, int*>::value, "");
+ }
+ {
+ typedef std::unique_ptr<VT, D3> P;
+ static_assert(std::is_same<typename P::pointer, int*>::value, "");
+ }
+#endif
+}
+
+int main() {
+ test_basic</*IsArray*/ false>();
+ test_basic<true>();
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <memory>
+
+// unique_ptr
+
+// Test unique_ptr move assignment
+
+// test move assignment. Should only require a MoveConstructible deleter, or if
+// deleter is a reference, not even that.
+
+#include <memory>
+#include <utility>
+#include <cassert>
+
+#include "deleter_types.h"
+#include "unique_ptr_test_helper.h"
+
+struct GenericDeleter {
+ void operator()(void*) const;
+};
+
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, A[], A>::type VT;
+ const int expect_alive = IsArray ? 5 : 1;
+ {
+ std::unique_ptr<VT> s1(newValue<VT>(expect_alive));
+ A* p = s1.get();
+ std::unique_ptr<VT> s2(newValue<VT>(expect_alive));
+ assert(A::count == (expect_alive * 2));
+ s2 = std::move(s1);
+ assert(A::count == expect_alive);
+ assert(s2.get() == p);
+ assert(s1.get() == 0);
+ }
+ assert(A::count == 0);
+ {
+ std::unique_ptr<VT, Deleter<VT> > s1(newValue<VT>(expect_alive),
+ Deleter<VT>(5));
+ A* p = s1.get();
+ std::unique_ptr<VT, Deleter<VT> > s2(newValue<VT>(expect_alive));
+ assert(A::count == (expect_alive * 2));
+ s2 = std::move(s1);
+ assert(s2.get() == p);
+ assert(s1.get() == 0);
+ assert(A::count == expect_alive);
+ assert(s2.get_deleter().state() == 5);
+ assert(s1.get_deleter().state() == 0);
+ }
+ assert(A::count == 0);
+ {
+ CDeleter<VT> d1(5);
+ std::unique_ptr<VT, CDeleter<VT>&> s1(newValue<VT>(expect_alive), d1);
+ A* p = s1.get();
+ CDeleter<VT> d2(6);
+ std::unique_ptr<VT, CDeleter<VT>&> s2(newValue<VT>(expect_alive), d2);
+ s2 = std::move(s1);
+ assert(s2.get() == p);
+ assert(s1.get() == 0);
+ assert(A::count == expect_alive);
+ assert(d1.state() == 5);
+ assert(d2.state() == 5);
+ }
+ assert(A::count == 0);
+}
+
+template <bool IsArray>
+void test_sfinae() {
+ typedef typename std::conditional<IsArray, int[], int>::type VT;
+ {
+ typedef std::unique_ptr<VT> U;
+ static_assert(!std::is_assignable<U, U&>::value, "");
+ static_assert(!std::is_assignable<U, const U&>::value, "");
+ static_assert(!std::is_assignable<U, const U&&>::value, "");
+ static_assert(std::is_assignable<U, U&&>::value, "");
+ }
+ {
+ typedef std::unique_ptr<VT, GenericDeleter> U;
+ static_assert(!std::is_assignable<U, U&>::value, "");
+ static_assert(!std::is_assignable<U, const U&>::value, "");
+ static_assert(!std::is_assignable<U, const U&&>::value, "");
+ static_assert(std::is_assignable<U, U&&>::value, "");
+ }
+ {
+ typedef std::unique_ptr<VT, NCDeleter<VT>&> U;
+ static_assert(!std::is_assignable<U, U&>::value, "");
+ static_assert(!std::is_assignable<U, const U&>::value, "");
+ static_assert(!std::is_assignable<U, const U&&>::value, "");
+ static_assert(std::is_assignable<U, U&&>::value, "");
+ }
+ {
+ typedef std::unique_ptr<VT, const NCDeleter<VT>&> U;
+ static_assert(!std::is_assignable<U, U&>::value, "");
+ static_assert(!std::is_assignable<U, const U&>::value, "");
+ static_assert(!std::is_assignable<U, const U&&>::value, "");
+ static_assert(std::is_assignable<U, U&&>::value, "");
+ }
+}
+
+int main() {
+ {
+ test_basic</*IsArray*/ false>();
+ test_sfinae<false>();
+ }
+ {
+ test_basic</*IsArray*/ true>();
+ test_sfinae<true>();
+ }
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <memory>
+
+// unique_ptr
+
+// Test unique_ptr converting move assignment
+
+#include <memory>
+#include <utility>
+#include <cassert>
+
+#include "unique_ptr_test_helper.h"
+
+template <class APtr, class BPtr>
+void testAssign(APtr& aptr, BPtr& bptr) {
+ A* p = bptr.get();
+ assert(A::count == 2);
+ aptr = std::move(bptr);
+ assert(aptr.get() == p);
+ assert(bptr.get() == 0);
+ assert(A::count == 1);
+ assert(B::count == 1);
+}
+
+template <class LHS, class RHS>
+void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) {
+ assert(lhs.get_deleter().state() == LHSState);
+ assert(rhs.get_deleter().state() == RHSState);
+}
+
+template <class T>
+struct NCConvertingDeleter {
+ NCConvertingDeleter() = default;
+ NCConvertingDeleter(NCConvertingDeleter const&) = delete;
+ NCConvertingDeleter(NCConvertingDeleter&&) = default;
+
+ template <class U>
+ NCConvertingDeleter(NCConvertingDeleter<U>&&) {}
+
+ void operator()(T*) const {}
+};
+
+template <class T>
+struct NCConvertingDeleter<T[]> {
+ NCConvertingDeleter() = default;
+ NCConvertingDeleter(NCConvertingDeleter const&) = delete;
+ NCConvertingDeleter(NCConvertingDeleter&&) = default;
+
+ template <class U>
+ NCConvertingDeleter(NCConvertingDeleter<U>&&) {}
+
+ void operator()(T*) const {}
+};
+
+struct GenericDeleter {
+ void operator()(void*) const;
+};
+
+struct NCGenericDeleter {
+ NCGenericDeleter() = default;
+ NCGenericDeleter(NCGenericDeleter const&) = delete;
+ NCGenericDeleter(NCGenericDeleter&&) = default;
+
+ void operator()(void*) const {}
+};
+
+void test_sfinae() {
+ using DA = NCConvertingDeleter<A[]>; // non-copyable deleters
+ using DAC = NCConvertingDeleter<const A[]>; // non-copyable deleters
+
+ using DB = NCConvertingDeleter<B[]>;
+ using UA = std::unique_ptr<A[]>;
+ using UAC = std::unique_ptr<const A[]>;
+ using UB = std::unique_ptr<B[]>;
+ using UAD = std::unique_ptr<A[], DA>;
+ using UACD = std::unique_ptr<const A[], DAC>;
+
+ using UBD = std::unique_ptr<B[], DB>;
+ { // cannot move from an lvalue
+ static_assert(std::is_assignable<UAC, UA&&>::value, "");
+ static_assert(!std::is_assignable<UAC, UA&>::value, "");
+ static_assert(!std::is_assignable<UAC, const UA&>::value, "");
+ }
+ { // cannot move if the deleter-types cannot convert
+ static_assert(std::is_assignable<UACD, UAD&&>::value, "");
+ static_assert(!std::is_assignable<UACD, UAC&&>::value, "");
+ static_assert(!std::is_assignable<UAC, UACD&&>::value, "");
+ }
+ { // cannot move-convert with reference deleters of different types
+ using UA1 = std::unique_ptr<A[], DA&>;
+ using UA2 = std::unique_ptr<A[], DAC&>;
+ static_assert(!std::is_assignable<UA1, UA2&&>::value, "");
+ }
+ { // cannot move-convert with reference deleters of different types
+ using UA1 = std::unique_ptr<A[], const DA&>;
+ using UA2 = std::unique_ptr<A[], const DAC&>;
+ static_assert(!std::is_assignable<UA1, UA2&&>::value, "");
+ }
+ { // cannot move-convert from unique_ptr<Single>
+ using UA1 = std::unique_ptr<A[]>;
+ using UA2 = std::unique_ptr<A>;
+ static_assert(!std::is_assignable<UA1, UA2&&>::value, "");
+ }
+ { // cannot move-convert from unique_ptr<Array[]>
+ using UA1 = std::unique_ptr<A[], NCGenericDeleter>;
+ using UA2 = std::unique_ptr<A, NCGenericDeleter>;
+ static_assert(!std::is_assignable<UA1, UA2&&>::value, "");
+ }
+}
+
+int main() {
+ test_sfinae();
+ // FIXME: add tests
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <memory>
+
+// unique_ptr
+
+// Test unique_ptr converting move assignment
+
+#include <memory>
+#include <utility>
+#include <cassert>
+
+#include "deleter_types.h"
+#include "unique_ptr_test_helper.h"
+
+template <class APtr, class BPtr>
+void testAssign(APtr& aptr, BPtr& bptr) {
+ A* p = bptr.get();
+ assert(A::count == 2);
+ aptr = std::move(bptr);
+ assert(aptr.get() == p);
+ assert(bptr.get() == 0);
+ assert(A::count == 1);
+ assert(B::count == 1);
+}
+
+template <class LHS, class RHS>
+void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) {
+ assert(lhs.get_deleter().state() == LHSState);
+ assert(rhs.get_deleter().state() == RHSState);
+}
+
+template <class T>
+struct NCConvertingDeleter {
+ NCConvertingDeleter() = default;
+ NCConvertingDeleter(NCConvertingDeleter const&) = delete;
+ NCConvertingDeleter(NCConvertingDeleter&&) = default;
+
+ template <class U>
+ NCConvertingDeleter(NCConvertingDeleter<U>&&) {}
+
+ void operator()(T*) const {}
+};
+
+template <class T>
+struct NCConvertingDeleter<T[]> {
+ NCConvertingDeleter() = default;
+ NCConvertingDeleter(NCConvertingDeleter const&) = delete;
+ NCConvertingDeleter(NCConvertingDeleter&&) = default;
+
+ template <class U>
+ NCConvertingDeleter(NCConvertingDeleter<U>&&) {}
+
+ void operator()(T*) const {}
+};
+
+struct NCGenericDeleter {
+ NCGenericDeleter() = default;
+ NCGenericDeleter(NCGenericDeleter const&) = delete;
+ NCGenericDeleter(NCGenericDeleter&&) = default;
+
+ void operator()(void*) const {}
+};
+
+void test_sfinae() {
+ using DA = NCConvertingDeleter<A>; // non-copyable deleters
+ using DB = NCConvertingDeleter<B>;
+ using UA = std::unique_ptr<A>;
+ using UB = std::unique_ptr<B>;
+ using UAD = std::unique_ptr<A, DA>;
+ using UBD = std::unique_ptr<B, DB>;
+ { // cannot move from an lvalue
+ static_assert(std::is_assignable<UA, UB&&>::value, "");
+ static_assert(!std::is_assignable<UA, UB&>::value, "");
+ static_assert(!std::is_assignable<UA, const UB&>::value, "");
+ }
+ { // cannot move if the deleter-types cannot convert
+ static_assert(std::is_assignable<UAD, UBD&&>::value, "");
+ static_assert(!std::is_assignable<UAD, UB&&>::value, "");
+ static_assert(!std::is_assignable<UA, UBD&&>::value, "");
+ }
+ { // cannot move-convert with reference deleters of different types
+ using UA1 = std::unique_ptr<A, DA&>;
+ using UB1 = std::unique_ptr<B, DB&>;
+ static_assert(!std::is_assignable<UA1, UB1&&>::value, "");
+ }
+ { // cannot move-convert with reference deleters of different types
+ using UA1 = std::unique_ptr<A, const DA&>;
+ using UB1 = std::unique_ptr<B, const DB&>;
+ static_assert(!std::is_assignable<UA1, UB1&&>::value, "");
+ }
+ { // cannot move-convert from unique_ptr<Array[]>
+ using UA1 = std::unique_ptr<A>;
+ using UA2 = std::unique_ptr<A[]>;
+ using UB1 = std::unique_ptr<B[]>;
+ static_assert(!std::is_assignable<UA1, UA2&&>::value, "");
+ static_assert(!std::is_assignable<UA1, UB1&&>::value, "");
+ }
+ { // cannot move-convert from unique_ptr<Array[]>
+ using UA1 = std::unique_ptr<A, NCGenericDeleter>;
+ using UA2 = std::unique_ptr<A[], NCGenericDeleter>;
+ using UB1 = std::unique_ptr<B[], NCGenericDeleter>;
+ static_assert(!std::is_assignable<UA1, UA2&&>::value, "");
+ static_assert(!std::is_assignable<UA1, UB1&&>::value, "");
+ }
+}
+
+int main() {
+ test_sfinae();
+ {
+ std::unique_ptr<B> bptr(new B);
+ std::unique_ptr<A> aptr(new A);
+ testAssign(aptr, bptr);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+ {
+ Deleter<B> del(42);
+ std::unique_ptr<B, Deleter<B> > bptr(new B, std::move(del));
+ std::unique_ptr<A, Deleter<A> > aptr(new A);
+ testAssign(aptr, bptr);
+ checkDeleter(aptr, bptr, 42, 0);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+ {
+ CDeleter<A> adel(6);
+ CDeleter<B> bdel(42);
+ std::unique_ptr<B, CDeleter<B>&> bptr(new B, bdel);
+ std::unique_ptr<A, CDeleter<A>&> aptr(new A, adel);
+ testAssign(aptr, bptr);
+ checkDeleter(aptr, bptr, 42, 42);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+}
#include <memory>
#include <cassert>
-// test assignment from null
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
+#include "unique_ptr_test_helper.h"
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A> s2(new A);
- assert(A::count == 1);
- s2 = 0;
+// test assignment from null
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, A[], A>::type VT;
+ const int expect_alive = IsArray ? 5 : 1;
+ {
+ std::unique_ptr<VT> s2(newValue<VT>(expect_alive));
+ assert(A::count == expect_alive);
+ s2 = NULL;
assert(A::count == 0);
assert(s2.get() == 0);
- }
- assert(A::count == 0);
+ }
+ assert(A::count == 0);
+}
+
+int main() {
+ test_basic</*IsArray*/ false>();
+ test_basic<true>();
}
#include <memory>
#include <cassert>
+#include "unique_ptr_test_helper.h"
+
// test assignment from null
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-int main()
-{
- {
- std::unique_ptr<A> s2(new A);
- assert(A::count == 1);
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, A[], A>::type VT;
+ const int expect_alive = IsArray ? 5 : 1;
+ {
+ std::unique_ptr<VT> s2(newValue<VT>(expect_alive));
+ assert(A::count == expect_alive);
s2 = nullptr;
assert(A::count == 0);
assert(s2.get() == 0);
- }
- assert(A::count == 0);
+ }
+ assert(A::count == 0);
+}
+
+int main() {
+ test_basic</*IsArray*/ false>();
+ test_basic<true>();
}
#include "test_macros.h"
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
+struct A {
+ static int count;
+ A() { ++count; }
+ A(const A&) { ++count; }
+ virtual ~A() { --count; }
};
int A::count = 0;
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
+struct B : public A {
+ static int count;
+ B() { ++count; }
+ B(const B&) { ++count; }
+ virtual ~B() { --count; }
};
int B::count = 0;
-int main()
-{
- {
+struct C {};
+
+struct Deleter {
+ void operator()(void*) {}
+};
+
+void test_sfinae() {
+ {
+ // the auto_ptr constructor should be disable with a non-default deleter.
+ using AP = std::auto_ptr<int>;
+ using U = std::unique_ptr<int, Deleter>;
+ static_assert(!std::is_constructible<U, AP&&>::value, "");
+ }
+ {
+ // the auto_ptr constructor should be disabled when the pointer types are incompatible.
+ using AP = std::auto_ptr<A>;
+ using U = std::unique_ptr<C>;
+ static_assert(!std::is_constructible<U, AP&&>::value, "");
+ }
+}
+
+int main() {
+ {
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up(std::move(ap));
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
- {
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+ {
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up;
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
#if TEST_STD_VER >= 11
- {
- static_assert(std::is_nothrow_constructible<
- std::unique_ptr<A>,
- std::auto_ptr<B>&&
- >::value, "");
- }
+ {
+ static_assert(std::is_nothrow_constructible<std::unique_ptr<A>,
+ std::auto_ptr<B>&&>::value,
+ "");
+ }
#endif
+ test_sfinae();
}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+//=============================================================================
+// TESTING std::unique_ptr::unique_ptr()
+//
+// Concerns:
+// 1 The default constructor works for any default constructible deleter types.
+// 2 The stored type 'T' is allowed to be incomplete.
+//
+// Plan
+// 1 Default construct unique_ptr's with various deleter types (C-1)
+// 2 Default construct a unique_ptr with an incomplete element_type and
+// various deleter types (C-1,2)
+
+#include <memory>
+#include <cassert>
+#include "test_macros.h"
+
+#include "test_macros.h"
+#include "deleter_types.h"
+#include "unique_ptr_test_helper.h"
+
+#include "test_workarounds.h" // For TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES
+
+#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11
+_LIBCPP_SAFE_STATIC std::unique_ptr<int> global_static_unique_ptr_single;
+_LIBCPP_SAFE_STATIC std::unique_ptr<int[]> global_static_unique_ptr_runtime;
+#endif
+
+#if TEST_STD_VER >= 11
+struct NonDefaultDeleter {
+ NonDefaultDeleter() = delete;
+ void operator()(void*) const {}
+};
+#endif
+
+template <class ElemType>
+void test_sfinae() {
+#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES)
+ { // the constructor does not participate in overload resultion when
+ // the deleter is a pointer type
+ using U = std::unique_ptr<ElemType, void (*)(void*)>;
+ static_assert(!std::is_default_constructible<U>::value, "");
+ }
+ { // the constructor does not participate in overload resolution when
+ // the deleter is not default constructible
+ using Del = CDeleter<ElemType>;
+ using U1 = std::unique_ptr<ElemType, NonDefaultDeleter>;
+ using U2 = std::unique_ptr<ElemType, Del&>;
+ using U3 = std::unique_ptr<ElemType, Del const&>;
+ static_assert(!std::is_default_constructible<U1>::value, "");
+ static_assert(!std::is_default_constructible<U2>::value, "");
+ static_assert(!std::is_default_constructible<U3>::value, "");
+ }
+#endif
+}
+
+template <class ElemType>
+void test_basic() {
+#if TEST_STD_VER >= 11
+ {
+ using U1 = std::unique_ptr<ElemType>;
+ using U2 = std::unique_ptr<ElemType, Deleter<ElemType> >;
+ static_assert(std::is_nothrow_default_constructible<U1>::value, "");
+ static_assert(std::is_nothrow_default_constructible<U2>::value, "");
+ }
+#endif
+ {
+ std::unique_ptr<ElemType> p;
+ assert(p.get() == 0);
+ }
+ {
+ std::unique_ptr<ElemType, NCDeleter<ElemType> > p;
+ assert(p.get() == 0);
+ assert(p.get_deleter().state() == 0);
+ p.get_deleter().set_state(5);
+ assert(p.get_deleter().state() == 5);
+ }
+}
+
+DEFINE_AND_RUN_IS_INCOMPLETE_TEST({
+ doIncompleteTypeTest(0);
+ doIncompleteTypeTest<IncompleteType, Deleter<IncompleteType> >(0);
+} {
+ doIncompleteTypeTest<IncompleteType[]>(0);
+ doIncompleteTypeTest<IncompleteType[], Deleter<IncompleteType[]> >(0);
+})
+
+int main() {
+ {
+ test_sfinae<int>();
+ test_basic<int>();
+ }
+ {
+ test_sfinae<int[]>();
+ test_basic<int[]>();
+ }
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// Test unique_ptr move ctor
+
+#include <memory>
+#include <utility>
+#include <cassert>
+
+#include "test_macros.h"
+#include "deleter_types.h"
+#include "unique_ptr_test_helper.h"
+
+//=============================================================================
+// TESTING unique_ptr(unique_ptr&&)
+//
+// Concerns
+// 1 The moved from pointer is empty and the new pointer stores the old value.
+// 2 The only requirement on the deleter is that it is MoveConstructible
+// or a reference.
+// 3 The constructor works for explicitly moved values (ie std::move(x))
+// 4 The constructor works for true temporaries (ie a return value)
+//
+// Plan
+// 1 Explicitly construct unique_ptr<T, D> for various deleter types 'D'.
+// check that the value and deleter have been properly moved. (C-1,2,3)
+//
+// 2 Use the expression 'sink(source())' to move construct a unique_ptr<T, D>
+// from a temporary. 'source' should return the unique_ptr by value and
+// 'sink' should accept the unique_ptr by value. (C-1,2,4)
+
+template <class VT>
+std::unique_ptr<VT> source1() {
+ return std::unique_ptr<VT>(newValue<VT>(1));
+}
+
+template <class VT>
+std::unique_ptr<VT, Deleter<VT> > source2() {
+ return std::unique_ptr<VT, Deleter<VT> >(newValue<VT>(1), Deleter<VT>(5));
+}
+
+template <class VT>
+std::unique_ptr<VT, NCDeleter<VT>&> source3() {
+ static NCDeleter<VT> d(5);
+ return std::unique_ptr<VT, NCDeleter<VT>&>(newValue<VT>(1), d);
+}
+
+template <class VT>
+void sink1(std::unique_ptr<VT> p) {
+ assert(p.get() != nullptr);
+}
+
+template <class VT>
+void sink2(std::unique_ptr<VT, Deleter<VT> > p) {
+ assert(p.get() != nullptr);
+ assert(p.get_deleter().state() == 5);
+}
+
+template <class VT>
+void sink3(std::unique_ptr<VT, NCDeleter<VT>&> p) {
+ assert(p.get() != nullptr);
+ assert(p.get_deleter().state() == 5);
+ assert(&p.get_deleter() == &source3<VT>().get_deleter());
+}
+
+template <class ValueT>
+void test_sfinae() {
+ typedef std::unique_ptr<ValueT> U;
+ { // Ensure unique_ptr is non-copyable
+ static_assert((!std::is_constructible<U, U const&>::value), "");
+ static_assert((!std::is_constructible<U, U&>::value), "");
+ }
+}
+
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<!IsArray, A, A[]>::type VT;
+ const int expect_alive = IsArray ? 5 : 1;
+ {
+ typedef std::unique_ptr<VT> APtr;
+ APtr s(newValue<VT>(expect_alive));
+ A* p = s.get();
+ APtr s2 = std::move(s);
+ assert(s2.get() == p);
+ assert(s.get() == 0);
+ assert(A::count == expect_alive);
+ }
+ assert(A::count == 0);
+ {
+ typedef Deleter<VT> MoveDel;
+ typedef std::unique_ptr<VT, MoveDel> APtr;
+ MoveDel d(5);
+ APtr s(newValue<VT>(expect_alive), std::move(d));
+ assert(d.state() == 0);
+ assert(s.get_deleter().state() == 5);
+ A* p = s.get();
+ APtr s2 = std::move(s);
+ assert(s2.get() == p);
+ assert(s.get() == 0);
+ assert(A::count == expect_alive);
+ assert(s2.get_deleter().state() == 5);
+ assert(s.get_deleter().state() == 0);
+ }
+ assert(A::count == 0);
+ {
+ typedef NCDeleter<VT> NonCopyDel;
+ typedef std::unique_ptr<VT, NonCopyDel&> APtr;
+
+ NonCopyDel d;
+ APtr s(newValue<VT>(expect_alive), d);
+ A* p = s.get();
+ APtr s2 = std::move(s);
+ assert(s2.get() == p);
+ assert(s.get() == 0);
+ assert(A::count == expect_alive);
+ d.set_state(6);
+ assert(s2.get_deleter().state() == d.state());
+ assert(s.get_deleter().state() == d.state());
+ }
+ assert(A::count == 0);
+ {
+ sink1<VT>(source1<VT>());
+ assert(A::count == 0);
+ sink2<VT>(source2<VT>());
+ assert(A::count == 0);
+ sink3<VT>(source3<VT>());
+ assert(A::count == 0);
+ }
+ assert(A::count == 0);
+}
+
+int main() {
+ {
+ test_basic</*IsArray*/ false>();
+ test_sfinae<int>();
+ }
+ {
+ test_basic</*IsArray*/ true>();
+ test_sfinae<int[]>();
+ }
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <memory>
+
+// unique_ptr
+
+// Test unique_ptr converting move ctor
+
+#include <memory>
+#include <cassert>
+
+#include "deleter_types.h"
+#include "unique_ptr_test_helper.h"
+
+template <int ID = 0>
+struct GenericDeleter {
+ void operator()(void*) const {}
+};
+
+template <int ID = 0>
+struct GenericConvertingDeleter {
+ template <int OID>
+ GenericConvertingDeleter(GenericConvertingDeleter<OID>) {}
+ void operator()(void*) const {}
+};
+
+void test_sfinae() {
+ { // Disallow copying
+ using U1 = std::unique_ptr<A[], GenericConvertingDeleter<0> >;
+ using U2 = std::unique_ptr<A[], GenericConvertingDeleter<1> >;
+ static_assert(std::is_constructible<U1, U2&&>::value, "");
+ static_assert(!std::is_constructible<U1, U2&>::value, "");
+ static_assert(!std::is_constructible<U1, const U2&>::value, "");
+ static_assert(!std::is_constructible<U1, const U2&&>::value, "");
+ }
+ { // Disallow illegal qualified conversions
+ using U1 = std::unique_ptr<const A[]>;
+ using U2 = std::unique_ptr<A[]>;
+ static_assert(std::is_constructible<U1, U2&&>::value, "");
+ static_assert(!std::is_constructible<U2, U1&&>::value, "");
+ }
+ { // Disallow base-to-derived conversions.
+ using UA = std::unique_ptr<A[]>;
+ using UB = std::unique_ptr<B[]>;
+ static_assert(!std::is_constructible<UA, UB&&>::value, "");
+ }
+ { // Disallow base-to-derived conversions.
+ using UA = std::unique_ptr<A[], GenericConvertingDeleter<0> >;
+ using UB = std::unique_ptr<B[], GenericConvertingDeleter<1> >;
+ static_assert(!std::is_constructible<UA, UB&&>::value, "");
+ }
+ { // Disallow invalid deleter initialization
+ using U1 = std::unique_ptr<A[], GenericDeleter<0> >;
+ using U2 = std::unique_ptr<A[], GenericDeleter<1> >;
+ static_assert(!std::is_constructible<U1, U2&&>::value, "");
+ }
+ { // Disallow reference deleters with different qualifiers
+ using U1 = std::unique_ptr<A[], Deleter<A[]>&>;
+ using U2 = std::unique_ptr<A[], const Deleter<A[]>&>;
+ static_assert(!std::is_constructible<U1, U2&&>::value, "");
+ static_assert(!std::is_constructible<U2, U1&&>::value, "");
+ }
+ {
+ using U1 = std::unique_ptr<A[]>;
+ using U2 = std::unique_ptr<A>;
+ static_assert(!std::is_constructible<U1, U2&&>::value, "");
+ static_assert(!std::is_constructible<U2, U1&&>::value, "");
+ }
+}
+
+int main() { test_sfinae(); }
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// Test unique_ptr converting move ctor
+
+// NOTE: unique_ptr does not provide converting constructors in c++03
+// UNSUPPORTED: c++98, c++03
+
+#include <memory>
+#include <type_traits>
+#include <utility>
+#include <cassert>
+
+#include "deleter_types.h"
+#include "unique_ptr_test_helper.h"
+
+// test converting move ctor. Should only require a MoveConstructible deleter, or if
+// deleter is a reference, not even that.
+// Explicit version
+
+template <class LHS, class RHS>
+void checkReferenceDeleter(LHS& lhs, RHS& rhs) {
+ typedef typename LHS::deleter_type NewDel;
+ static_assert(std::is_reference<NewDel>::value, "");
+ rhs.get_deleter().set_state(42);
+ assert(rhs.get_deleter().state() == 42);
+ assert(lhs.get_deleter().state() == 42);
+ lhs.get_deleter().set_state(99);
+ assert(lhs.get_deleter().state() == 99);
+ assert(rhs.get_deleter().state() == 99);
+}
+
+template <class LHS, class RHS>
+void checkDeleter(LHS& lhs, RHS& rhs, int LHSVal, int RHSVal) {
+ assert(lhs.get_deleter().state() == LHSVal);
+ assert(rhs.get_deleter().state() == RHSVal);
+}
+
+template <class LHS, class RHS>
+void checkCtor(LHS& lhs, RHS& rhs, A* RHSVal) {
+ assert(lhs.get() == RHSVal);
+ assert(rhs.get() == nullptr);
+ assert(A::count == 1);
+ assert(B::count == 1);
+}
+
+void checkNoneAlive() {
+ assert(A::count == 0);
+ assert(B::count == 0);
+}
+
+template <class T>
+struct NCConvertingDeleter {
+ NCConvertingDeleter() = default;
+ NCConvertingDeleter(NCConvertingDeleter const&) = delete;
+ NCConvertingDeleter(NCConvertingDeleter&&) = default;
+
+ template <class U>
+ NCConvertingDeleter(NCConvertingDeleter<U>&&) {}
+
+ void operator()(T*) const {}
+};
+
+template <class T>
+struct NCConvertingDeleter<T[]> {
+ NCConvertingDeleter() = default;
+ NCConvertingDeleter(NCConvertingDeleter const&) = delete;
+ NCConvertingDeleter(NCConvertingDeleter&&) = default;
+
+ template <class U>
+ NCConvertingDeleter(NCConvertingDeleter<U>&&) {}
+
+ void operator()(T*) const {}
+};
+
+struct NCGenericDeleter {
+ NCGenericDeleter() = default;
+ NCGenericDeleter(NCGenericDeleter const&) = delete;
+ NCGenericDeleter(NCGenericDeleter&&) = default;
+
+ void operator()(void*) const {}
+};
+
+void test_sfinae() {
+ using DA = NCConvertingDeleter<A>; // non-copyable deleters
+ using DB = NCConvertingDeleter<B>;
+ using UA = std::unique_ptr<A>;
+ using UB = std::unique_ptr<B>;
+ using UAD = std::unique_ptr<A, DA>;
+ using UBD = std::unique_ptr<B, DB>;
+ { // cannot move from an lvalue
+ static_assert(std::is_constructible<UA, UB&&>::value, "");
+ static_assert(!std::is_constructible<UA, UB&>::value, "");
+ static_assert(!std::is_constructible<UA, const UB&>::value, "");
+ }
+ { // cannot move if the deleter-types cannot convert
+ static_assert(std::is_constructible<UAD, UBD&&>::value, "");
+ static_assert(!std::is_constructible<UAD, UB&&>::value, "");
+ static_assert(!std::is_constructible<UA, UBD&&>::value, "");
+ }
+ { // cannot move-convert with reference deleters of different types
+ using UA1 = std::unique_ptr<A, DA&>;
+ using UB1 = std::unique_ptr<B, DB&>;
+ static_assert(!std::is_constructible<UA1, UB1&&>::value, "");
+ }
+ { // cannot move-convert with reference deleters of different types
+ using UA1 = std::unique_ptr<A, const DA&>;
+ using UB1 = std::unique_ptr<B, const DB&>;
+ static_assert(!std::is_constructible<UA1, UB1&&>::value, "");
+ }
+ { // cannot move-convert from unique_ptr<Array[]>
+ using UA1 = std::unique_ptr<A>;
+ using UA2 = std::unique_ptr<A[]>;
+ using UB1 = std::unique_ptr<B[]>;
+ static_assert(!std::is_constructible<UA1, UA2&&>::value, "");
+ static_assert(!std::is_constructible<UA1, UB1&&>::value, "");
+ }
+ { // cannot move-convert from unique_ptr<Array[]>
+ using UA1 = std::unique_ptr<A, NCGenericDeleter>;
+ using UA2 = std::unique_ptr<A[], NCGenericDeleter>;
+ using UB1 = std::unique_ptr<B[], NCGenericDeleter>;
+ static_assert(!std::is_constructible<UA1, UA2&&>::value, "");
+ static_assert(!std::is_constructible<UA1, UB1&&>::value, "");
+ }
+}
+
+int main() {
+ {
+ typedef std::unique_ptr<A> APtr;
+ typedef std::unique_ptr<B> BPtr;
+ { // explicit
+ BPtr b(new B);
+ A* p = b.get();
+ APtr a(std::move(b));
+ checkCtor(a, b, p);
+ }
+ checkNoneAlive();
+ { // implicit
+ BPtr b(new B);
+ A* p = b.get();
+ APtr a = std::move(b);
+ checkCtor(a, b, p);
+ }
+ checkNoneAlive();
+ }
+ { // test with moveable deleters
+ typedef std::unique_ptr<A, Deleter<A> > APtr;
+ typedef std::unique_ptr<B, Deleter<B> > BPtr;
+ {
+ Deleter<B> del(5);
+ BPtr b(new B, std::move(del));
+ A* p = b.get();
+ APtr a(std::move(b));
+ checkCtor(a, b, p);
+ checkDeleter(a, b, 5, 0);
+ }
+ checkNoneAlive();
+ {
+ Deleter<B> del(5);
+ BPtr b(new B, std::move(del));
+ A* p = b.get();
+ APtr a = std::move(b);
+ checkCtor(a, b, p);
+ checkDeleter(a, b, 5, 0);
+ }
+ checkNoneAlive();
+ }
+ { // test with reference deleters
+ typedef std::unique_ptr<A, NCDeleter<A>&> APtr;
+ typedef std::unique_ptr<B, NCDeleter<A>&> BPtr;
+ NCDeleter<A> del(5);
+ {
+ BPtr b(new B, del);
+ A* p = b.get();
+ APtr a(std::move(b));
+ checkCtor(a, b, p);
+ checkReferenceDeleter(a, b);
+ }
+ checkNoneAlive();
+ {
+ BPtr b(new B, del);
+ A* p = b.get();
+ APtr a = std::move(b);
+ checkCtor(a, b, p);
+ checkReferenceDeleter(a, b);
+ }
+ checkNoneAlive();
+ }
+ {
+ typedef std::unique_ptr<A, CDeleter<A> > APtr;
+ typedef std::unique_ptr<B, CDeleter<B>&> BPtr;
+ CDeleter<B> del(5);
+ {
+ BPtr b(new B, del);
+ A* p = b.get();
+ APtr a(std::move(b));
+ checkCtor(a, b, p);
+ checkDeleter(a, b, 5, 5);
+ }
+ checkNoneAlive();
+ {
+ BPtr b(new B, del);
+ A* p = b.get();
+ APtr a = std::move(b);
+ checkCtor(a, b, p);
+ checkDeleter(a, b, 5, 5);
+ }
+ checkNoneAlive();
+ }
+ test_sfinae();
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <memory>
+
+// unique_ptr
+
+// FIXME(EricWF): This test contains tests for constructing a unique_ptr from NULL.
+// The behavior demonstrated in this test is not meant to be standard; It simply
+// tests the current status quo in libc++.
+
+#include <memory>
+#include <cassert>
+
+#include "test_macros.h"
+#include "unique_ptr_test_helper.h"
+
+template <class VT>
+void test_pointer_ctor() {
+ {
+ std::unique_ptr<VT> p(0);
+ assert(p.get() == 0);
+ }
+ {
+ std::unique_ptr<VT, Deleter<VT> > p(0);
+ assert(p.get() == 0);
+ assert(p.get_deleter().state() == 0);
+ }
+}
+
+template <class VT>
+void test_pointer_deleter_ctor() {
+ {
+ std::default_delete<VT> d;
+ std::unique_ptr<VT> p(0, d);
+ assert(p.get() == 0);
+ }
+ {
+ std::unique_ptr<VT, Deleter<VT> > p(0, Deleter<VT>(5));
+ assert(p.get() == 0);
+ assert(p.get_deleter().state() == 5);
+ }
+ {
+ NCDeleter<VT> d(5);
+ std::unique_ptr<VT, NCDeleter<VT>&> p(0, d);
+ assert(p.get() == 0);
+ assert(p.get_deleter().state() == 5);
+ }
+ {
+ NCConstDeleter<VT> d(5);
+ std::unique_ptr<VT, NCConstDeleter<VT> const&> p(0, d);
+ assert(p.get() == 0);
+ assert(p.get_deleter().state() == 5);
+ }
+}
+
+int main() {
+ {
+ // test_pointer_ctor<int>();
+ test_pointer_deleter_ctor<int>();
+ }
+ {
+ test_pointer_ctor<int[]>();
+ test_pointer_deleter_ctor<int[]>();
+ }
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// unique_ptr(nullptr_t);
+
+#include <memory>
+#include <cassert>
+
+#include "test_macros.h"
+#include "deleter_types.h"
+#include "unique_ptr_test_helper.h"
+
+#include "test_workarounds.h" // For TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES
+
+// default unique_ptr ctor should only require default Deleter ctor
+class DefaultDeleter {
+ int state_;
+
+ DefaultDeleter(DefaultDeleter&);
+ DefaultDeleter& operator=(DefaultDeleter&);
+
+public:
+ DefaultDeleter() : state_(5) {}
+
+ int state() const { return state_; }
+
+ void operator()(void*) {}
+};
+
+#if TEST_STD_VER >= 11
+struct NonDefaultDeleter {
+ NonDefaultDeleter() = delete;
+ void operator()(void*) const {}
+};
+#endif
+
+template <class VT>
+void test_basic() {
+ {
+ std::unique_ptr<VT> p(nullptr);
+ assert(p.get() == 0);
+ }
+ {
+ std::unique_ptr<VT, DefaultDeleter> p(nullptr);
+ assert(p.get() == 0);
+ assert(p.get_deleter().state() == 5);
+ }
+#if TEST_STD_VER >= 11
+ {
+ using U1 = std::unique_ptr<VT>;
+ using U2 = std::unique_ptr<VT, Deleter<VT> >;
+ static_assert(std::is_nothrow_constructible<U1, decltype(nullptr)>::value,
+ "");
+ static_assert(std::is_nothrow_constructible<U2, decltype(nullptr)>::value,
+ "");
+ }
+#endif
+}
+
+template <class VT>
+void test_sfinae() {
+#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES)
+ { // the constructor does not participate in overload resultion when
+ // the deleter is a pointer type
+ using U = std::unique_ptr<VT, void (*)(void*)>;
+ static_assert(!std::is_constructible<U, decltype(nullptr)>::value, "");
+ }
+ { // the constructor does not participate in overload resolution when
+ // the deleter is not default constructible
+ using Del = CDeleter<VT>;
+ using U1 = std::unique_ptr<VT, NonDefaultDeleter>;
+ using U2 = std::unique_ptr<VT, Del&>;
+ using U3 = std::unique_ptr<VT, Del const&>;
+ static_assert(!std::is_constructible<U1, decltype(nullptr)>::value, "");
+ static_assert(!std::is_constructible<U2, decltype(nullptr)>::value, "");
+ static_assert(!std::is_constructible<U3, decltype(nullptr)>::value, "");
+ }
+#endif
+}
+
+DEFINE_AND_RUN_IS_INCOMPLETE_TEST({
+ { doIncompleteTypeTest(0, nullptr); }
+ checkNumIncompleteTypeAlive(0);
+ {
+ doIncompleteTypeTest<IncompleteType, NCDeleter<IncompleteType> >(0,
+ nullptr);
+ }
+ checkNumIncompleteTypeAlive(0);
+ { doIncompleteTypeTest<IncompleteType[]>(0, nullptr); }
+ checkNumIncompleteTypeAlive(0);
+ {
+ doIncompleteTypeTest<IncompleteType[], NCDeleter<IncompleteType[]> >(
+ 0, nullptr);
+ }
+ checkNumIncompleteTypeAlive(0);
+})
+
+int main() {
+ {
+ test_basic<int>();
+ test_sfinae<int>();
+ }
+ {
+ test_basic<int[]>();
+ test_sfinae<int[]>();
+ }
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+//=============================================================================
+// TESTING std::unique_ptr::unique_ptr(pointer)
+//
+// Concerns:
+// 1 The pointer constructor works for any default constructible deleter types.
+// 2 The pointer constructor accepts pointers to derived types.
+// 2 The stored type 'T' is allowed to be incomplete.
+//
+// Plan
+// 1 Construct unique_ptr<T, D>'s with a pointer to 'T' and various deleter
+// types (C-1)
+// 2 Construct unique_ptr<T, D>'s with a pointer to 'D' and various deleter
+// types where 'D' is derived from 'T'. (C-1,2)
+// 3 Construct a unique_ptr<T, D> with a pointer to 'T' and various deleter
+// types where 'T' is an incomplete type (C-1,3)
+
+// Test unique_ptr(pointer) ctor
+
+#include <memory>
+#include <cassert>
+
+#include "test_macros.h"
+#include "unique_ptr_test_helper.h"
+
+#include "test_workarounds.h" // For TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES
+
+// unique_ptr(pointer) ctor should only require default Deleter ctor
+
+template <bool IsArray>
+void test_pointer() {
+ typedef typename std::conditional<!IsArray, A, A[]>::type ValueT;
+ const int expect_alive = IsArray ? 5 : 1;
+#if TEST_STD_VER >= 11
+ {
+ using U1 = std::unique_ptr<ValueT>;
+ using U2 = std::unique_ptr<ValueT, Deleter<ValueT> >;
+ static_assert(std::is_nothrow_constructible<U1, A*>::value, "");
+ static_assert(std::is_nothrow_constructible<U2, A*>::value, "");
+ }
+#endif
+ {
+ A* p = newValue<ValueT>(expect_alive);
+ assert(A::count == expect_alive);
+ std::unique_ptr<ValueT> s(p);
+ assert(s.get() == p);
+ }
+ assert(A::count == 0);
+ {
+ A* p = newValue<ValueT>(expect_alive);
+ assert(A::count == expect_alive);
+ std::unique_ptr<ValueT, NCDeleter<ValueT> > s(p);
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 0);
+ }
+ assert(A::count == 0);
+}
+
+void test_derived() {
+ {
+ B* p = new B;
+ assert(A::count == 1);
+ assert(B::count == 1);
+ std::unique_ptr<A> s(p);
+ assert(s.get() == p);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+ {
+ B* p = new B;
+ assert(A::count == 1);
+ assert(B::count == 1);
+ std::unique_ptr<A, NCDeleter<A> > s(p);
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 0);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+}
+
+#if TEST_STD_VER >= 11
+struct NonDefaultDeleter {
+ NonDefaultDeleter() = delete;
+ void operator()(void*) const {}
+};
+
+struct GenericDeleter {
+ void operator()(void*) const;
+};
+#endif
+
+template <class T>
+void test_sfinae() {
+#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES)
+ { // the constructor does not participate in overload resultion when
+ // the deleter is a pointer type
+ using U = std::unique_ptr<T, void (*)(void*)>;
+ static_assert(!std::is_constructible<U, T*>::value, "");
+ }
+ { // the constructor does not participate in overload resolution when
+ // the deleter is not default constructible
+ using Del = CDeleter<T>;
+ using U1 = std::unique_ptr<T, NonDefaultDeleter>;
+ using U2 = std::unique_ptr<T, Del&>;
+ using U3 = std::unique_ptr<T, Del const&>;
+ static_assert(!std::is_constructible<U1, T*>::value, "");
+ static_assert(!std::is_constructible<U2, T*>::value, "");
+ static_assert(!std::is_constructible<U3, T*>::value, "");
+ }
+#endif
+}
+
+static void test_sfinae_runtime() {
+#if TEST_STD_VER >= 11
+ { // the constructor does not participate in overload resolution when
+ // a base <-> derived conversion would occur.
+ using UA = std::unique_ptr<A[]>;
+ using UAD = std::unique_ptr<A[], GenericDeleter>;
+ using UAC = std::unique_ptr<const A[]>;
+ using UB = std::unique_ptr<B[]>;
+ using UBD = std::unique_ptr<B[], GenericDeleter>;
+ using UBC = std::unique_ptr<const B[]>;
+
+ static_assert(!std::is_constructible<UA, B*>::value, "");
+ static_assert(!std::is_constructible<UB, A*>::value, "");
+ static_assert(!std::is_constructible<UAD, B*>::value, "");
+ static_assert(!std::is_constructible<UBD, A*>::value, "");
+ static_assert(!std::is_constructible<UAC, const B*>::value, "");
+ static_assert(!std::is_constructible<UBC, const A*>::value, "");
+ }
+#endif
+}
+
+DEFINE_AND_RUN_IS_INCOMPLETE_TEST({
+ { doIncompleteTypeTest(1, getNewIncomplete()); }
+ checkNumIncompleteTypeAlive(0);
+ {
+ doIncompleteTypeTest<IncompleteType, NCDeleter<IncompleteType> >(
+ 1, getNewIncomplete());
+ }
+ checkNumIncompleteTypeAlive(0);
+})
+
+int main() {
+ {
+ test_pointer</*IsArray*/ false>();
+ test_derived();
+ test_sfinae<int>();
+ }
+ {
+ test_pointer</*IsArray*/ true>();
+ test_sfinae<int[]>();
+ test_sfinae_runtime();
+ }
+}
#include <memory>
+#include "test_workarounds.h"
+
struct Deleter {
- void operator()(int* p) const {delete p;}
+ void operator()(int* p) const { delete p; }
};
-int main()
-{
- // expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}}
- std::unique_ptr<int, const Deleter&> s((int*)nullptr, Deleter()); // expected-note {{requested here}}
+int main() {
+#if defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES)
+// expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}}
+#else
+// expected-error@+2 {{call to deleted constructor of 'std::unique_ptr<int, const Deleter &>}}
+#endif
+ std::unique_ptr<int, const Deleter&> s((int*)nullptr, Deleter());
}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+//=============================================================================
+// TESTING unique_ptr(pointer, deleter)
+//
+// Concerns:
+// 1 unique_ptr(pointer, deleter&&) only requires a MoveConstructible deleter.
+// 2 unique_ptr(pointer, deleter&) requires a CopyConstructible deleter.
+// 3 unique_ptr<T, D&>(pointer, deleter) does not require a CopyConstructible deleter.
+// 4 unique_ptr<T, D const&>(pointer, deleter) does not require a CopyConstructible deleter.
+// 5 unique_ptr(pointer, deleter) should work for derived pointers.
+// 6 unique_ptr(pointer, deleter) should work with function pointers.
+// 7 unique_ptr<void> should work.
+
+#include <memory>
+#include <cassert>
+
+#include "test_macros.h"
+#include "unique_ptr_test_helper.h"
+
+#include "test_workarounds.h" // For TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES
+
+bool my_free_called = false;
+
+void my_free(void*) { my_free_called = true; }
+
+#if TEST_STD_VER >= 11
+struct DeleterBase {
+ void operator()(void*) const {}
+};
+struct CopyOnlyDeleter : DeleterBase {
+ CopyOnlyDeleter() = default;
+ CopyOnlyDeleter(CopyOnlyDeleter const&) = default;
+ CopyOnlyDeleter(CopyOnlyDeleter&&) = delete;
+};
+struct MoveOnlyDeleter : DeleterBase {
+ MoveOnlyDeleter() = default;
+ MoveOnlyDeleter(MoveOnlyDeleter&&) = default;
+};
+struct NoCopyMoveDeleter : DeleterBase {
+ NoCopyMoveDeleter() = default;
+ NoCopyMoveDeleter(NoCopyMoveDeleter const&) = delete;
+};
+#endif
+
+template <bool IsArray>
+void test_sfinae() {
+#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES)
+ typedef typename std::conditional<!IsArray, int, int[]>::type VT;
+ {
+ using D = CopyOnlyDeleter;
+ using U = std::unique_ptr<VT, D>;
+ static_assert(std::is_constructible<U, int*, D const&>::value, "");
+ static_assert(std::is_constructible<U, int*, D&>::value, "");
+ static_assert(std::is_constructible<U, int*, D&&>::value, "");
+ // FIXME: __libcpp_compressed_pair attempts to perform a move even though
+ // it should only copy.
+ //D d;
+ //U u(nullptr, std::move(d));
+ }
+ {
+ using D = MoveOnlyDeleter;
+ using U = std::unique_ptr<VT, D>;
+ static_assert(!std::is_constructible<U, int*, D const&>::value, "");
+ static_assert(!std::is_constructible<U, int*, D&>::value, "");
+ static_assert(std::is_constructible<U, int*, D&&>::value, "");
+ D d;
+ U u(nullptr, std::move(d));
+ }
+ {
+ using D = NoCopyMoveDeleter;
+ using U = std::unique_ptr<VT, D>;
+ static_assert(!std::is_constructible<U, int*, D const&>::value, "");
+ static_assert(!std::is_constructible<U, int*, D&>::value, "");
+ static_assert(!std::is_constructible<U, int*, D&&>::value, "");
+ }
+ {
+ using D = NoCopyMoveDeleter;
+ using U = std::unique_ptr<VT, D&>;
+ static_assert(!std::is_constructible<U, int*, D const&>::value, "");
+ static_assert(std::is_constructible<U, int*, D&>::value, "");
+ static_assert(!std::is_constructible<U, int*, D&&>::value, "");
+ static_assert(!std::is_constructible<U, int*, const D&&>::value, "");
+ }
+ {
+ using D = NoCopyMoveDeleter;
+ using U = std::unique_ptr<VT, const D&>;
+ static_assert(std::is_constructible<U, int*, D const&>::value, "");
+ static_assert(std::is_constructible<U, int*, D&>::value, "");
+ static_assert(!std::is_constructible<U, int*, D&&>::value, "");
+ static_assert(!std::is_constructible<U, int*, const D&&>::value, "");
+ }
+#endif
+}
+
+template <bool IsArray>
+void test_noexcept() {
+#if TEST_STD_VER >= 11
+ typedef typename std::conditional<!IsArray, int, int[]>::type VT;
+ {
+ using D = CopyOnlyDeleter;
+ using U = std::unique_ptr<VT, D>;
+ static_assert(std::is_nothrow_constructible<U, int*, D const&>::value, "");
+ static_assert(std::is_nothrow_constructible<U, int*, D&>::value, "");
+ static_assert(std::is_nothrow_constructible<U, int*, D&&>::value, "");
+ }
+ {
+ using D = MoveOnlyDeleter;
+ using U = std::unique_ptr<VT, D>;
+ static_assert(std::is_nothrow_constructible<U, int*, D&&>::value, "");
+ D d;
+ U u(nullptr, std::move(d));
+ }
+ {
+ using D = NoCopyMoveDeleter;
+ using U = std::unique_ptr<VT, D&>;
+ static_assert(std::is_nothrow_constructible<U, int*, D&>::value, "");
+ }
+ {
+ using D = NoCopyMoveDeleter;
+ using U = std::unique_ptr<VT, const D&>;
+ static_assert(std::is_nothrow_constructible<U, int*, D const&>::value, "");
+ static_assert(std::is_nothrow_constructible<U, int*, D&>::value, "");
+ }
+#endif
+}
+
+void test_sfinae_runtime() {
+#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES)
+ {
+ using D = CopyOnlyDeleter;
+ using U = std::unique_ptr<A[], D>;
+ static_assert(std::is_constructible<U, A*, D const&>::value, "");
+ static_assert(std::is_constructible<U, A*, D&>::value, "");
+ static_assert(std::is_constructible<U, A*, D&&>::value, "");
+
+ static_assert(!std::is_constructible<U, B*, D const&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&&>::value, "");
+ // FIXME: __libcpp_compressed_pair attempts to perform a move even though
+ // it should only copy.
+ //D d;
+ //U u(nullptr, std::move(d));
+ }
+ {
+ using D = MoveOnlyDeleter;
+ using U = std::unique_ptr<A[], D>;
+ static_assert(!std::is_constructible<U, A*, D const&>::value, "");
+ static_assert(!std::is_constructible<U, A*, D&>::value, "");
+ static_assert(std::is_constructible<U, A*, D&&>::value, "");
+
+ static_assert(!std::is_constructible<U, B*, D const&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&&>::value, "");
+ D d;
+ U u(nullptr, std::move(d));
+ }
+ {
+ using D = NoCopyMoveDeleter;
+ using U = std::unique_ptr<A[], D>;
+ static_assert(!std::is_constructible<U, A*, D const&>::value, "");
+ static_assert(!std::is_constructible<U, A*, D&>::value, "");
+ static_assert(!std::is_constructible<U, A*, D&&>::value, "");
+
+ static_assert(!std::is_constructible<U, B*, D const&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&&>::value, "");
+ }
+ {
+ using D = NoCopyMoveDeleter;
+ using U = std::unique_ptr<A[], D&>;
+ static_assert(!std::is_constructible<U, A*, D const&>::value, "");
+ static_assert(std::is_constructible<U, A*, D&>::value, "");
+ static_assert(!std::is_constructible<U, A*, D&&>::value, "");
+ static_assert(!std::is_constructible<U, A*, const D&&>::value, "");
+
+ static_assert(!std::is_constructible<U, B*, D const&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&&>::value, "");
+ static_assert(!std::is_constructible<U, B*, const D&&>::value, "");
+ }
+ {
+ using D = NoCopyMoveDeleter;
+ using U = std::unique_ptr<A[], const D&>;
+ static_assert(std::is_constructible<U, A*, D const&>::value, "");
+ static_assert(std::is_constructible<U, A*, D&>::value, "");
+ static_assert(!std::is_constructible<U, A*, D&&>::value, "");
+ static_assert(!std::is_constructible<U, A*, const D&&>::value, "");
+
+ static_assert(!std::is_constructible<U, B*, D const&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&>::value, "");
+ static_assert(!std::is_constructible<U, B*, D&&>::value, "");
+ static_assert(!std::is_constructible<U, B*, const D&&>::value, "");
+ }
+#endif
+}
+
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<!IsArray, A, A[]>::type VT;
+ const int expect_alive = IsArray ? 5 : 1;
+ { // MoveConstructible deleter (C-1)
+ A* p = newValue<VT>(expect_alive);
+ assert(A::count == expect_alive);
+ std::unique_ptr<VT, Deleter<VT> > s(p, Deleter<VT>(5));
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 5);
+ }
+ assert(A::count == 0);
+ { // CopyConstructible deleter (C-2)
+ A* p = newValue<VT>(expect_alive);
+ assert(A::count == expect_alive);
+ CopyDeleter<VT> d(5);
+ std::unique_ptr<VT, CopyDeleter<VT> > s(p, d);
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 5);
+ d.set_state(6);
+ assert(s.get_deleter().state() == 5);
+ }
+ assert(A::count == 0);
+ { // Reference deleter (C-3)
+ A* p = newValue<VT>(expect_alive);
+ assert(A::count == expect_alive);
+ NCDeleter<VT> d(5);
+ std::unique_ptr<VT, NCDeleter<VT>&> s(p, d);
+ assert(s.get() == p);
+ assert(&s.get_deleter() == &d);
+ assert(s.get_deleter().state() == 5);
+ d.set_state(6);
+ assert(s.get_deleter().state() == 6);
+ }
+ assert(A::count == 0);
+ { // Const Reference deleter (C-4)
+ A* p = newValue<VT>(expect_alive);
+ assert(A::count == expect_alive);
+ NCConstDeleter<VT> d(5);
+ std::unique_ptr<VT, NCConstDeleter<VT> const&> s(p, d);
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 5);
+ assert(&s.get_deleter() == &d);
+ }
+ assert(A::count == 0);
+ { // Void and function pointers (C-6,7)
+ typedef typename std::conditional<IsArray, int[], int>::type VT2;
+ my_free_called = false;
+ {
+ int i = 0;
+ std::unique_ptr<VT2, void (*)(void*)> s(&i, my_free);
+ assert(s.get() == &i);
+ assert(s.get_deleter() == my_free);
+ assert(!my_free_called);
+ }
+ assert(my_free_called);
+ }
+}
+
+void test_basic_single() {
+ assert(A::count == 0);
+ assert(B::count == 0);
+ { // Derived pointers (C-5)
+ B* p = new B;
+ assert(A::count == 1);
+ assert(B::count == 1);
+ std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>(5));
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 5);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+ { // Void and function pointers (C-6,7)
+ my_free_called = false;
+ {
+ int i = 0;
+ std::unique_ptr<void, void (*)(void*)> s(&i, my_free);
+ assert(s.get() == &i);
+ assert(s.get_deleter() == my_free);
+ assert(!my_free_called);
+ }
+ assert(my_free_called);
+ }
+}
+
+int main() {
+ {
+ test_basic</*IsArray*/ false>();
+ test_basic_single();
+ test_sfinae<false>();
+ test_noexcept<false>();
+ }
+ {
+ test_basic</*IsArray*/ true>();
+ test_sfinae<true>();
+ test_sfinae_runtime();
+ test_noexcept<true>();
+ }
+}
#include <memory>
#include <cassert>
-class Deleter
-{
- int state_;
+class Deleter {
+ int state_;
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
+ Deleter(Deleter&);
+ Deleter& operator=(Deleter&);
public:
- Deleter() : state_(0) {}
+ Deleter() : state_(0) {}
- int state() const {return state_;}
+ int state() const { return state_; }
- void operator()(void*) {++state_;}
+ void operator()(void*) { ++state_; }
};
-int main()
-{
- Deleter d;
- assert(d.state() == 0);
- {
- std::unique_ptr<int, Deleter&> p(0, d);
+template <class T>
+void test_basic() {
+ Deleter d;
+ assert(d.state() == 0);
+ {
+ std::unique_ptr<T, Deleter&> p(0, d);
assert(p.get() == 0);
assert(&p.get_deleter() == &d);
- }
- assert(d.state() == 0);
+ }
+ assert(d.state() == 0);
+}
+
+int main() {
+ test_basic<int>();
+ test_basic<int[]>();
}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// test release
+
+#include <memory>
+#include <cassert>
+
+#include "unique_ptr_test_helper.h"
+
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, A[], A>::type VT;
+ const int expect_alive = IsArray ? 3 : 1;
+ {
+ std::unique_ptr<VT> p(newValue<VT>(expect_alive));
+ assert(A::count == expect_alive);
+ A* ap = p.get();
+ A* a = p.release();
+ assert(A::count == expect_alive);
+ assert(p.get() == nullptr);
+ assert(ap == a);
+ assert(a != nullptr);
+
+ if (IsArray)
+ delete[] a;
+ else
+ delete a;
+
+ assert(A::count == 0);
+ }
+ assert(A::count == 0);
+}
+
+int main() {
+ test_basic</*IsArray*/ false>();
+ test_basic<true>();
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// test reset
+
+#include <memory>
+#include <cassert>
+
+#include "unique_ptr_test_helper.h"
+
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, A[], A>::type VT;
+ const int expect_alive = IsArray ? 3 : 1;
+ {
+ std::unique_ptr<VT> p(newValue<VT>(expect_alive));
+ assert(A::count == expect_alive);
+ A* i = p.get();
+ assert(i != nullptr);
+ p.reset();
+ assert(A::count == 0);
+ assert(p.get() == 0);
+ }
+ assert(A::count == 0);
+ {
+ std::unique_ptr<VT> p(newValue<VT>(expect_alive));
+ assert(A::count == expect_alive);
+ A* i = p.get();
+ assert(i != nullptr);
+ A* new_value = newValue<VT>(expect_alive);
+ assert(A::count == (expect_alive * 2));
+ p.reset(new_value);
+ assert(A::count == expect_alive);
+ }
+ assert(A::count == 0);
+}
+
+int main() {
+ test_basic</*IsArray*/ false>();
+ test_basic<true>();
+}
// unique_ptr
-// test op*()
+// test reset
#include <memory>
#include <cassert>
-int main()
-{
- {
- std::unique_ptr<int[]> p(new int [3]);
- if (p)
- ;
- else
- assert(false);
- if (!p)
- assert(false);
- }
- {
+#include "unique_ptr_test_helper.h"
+
+int main() {
+ {
+ std::unique_ptr<A[]> p;
+ p.reset(static_cast<B*>(nullptr)); // expected-error {{no matching member function for call to 'reset'}}
+ }
+ {
std::unique_ptr<int[]> p;
- if (!p)
- ;
- else
- assert(false);
- if (p)
- assert(false);
- }
+ p.reset(static_cast<const int*>(nullptr)); // expected-error {{no matching member function for call to 'reset'}}
+ }
}
#include <memory>
#include <cassert>
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
-};
+#include "unique_ptr_test_helper.h"
-int A::count = 0;
-
-struct B
- : public A
-{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
-};
-
-int B::count = 0;
-
-int main()
-{
- {
+int main() {
+ {
std::unique_ptr<A> p(new A);
assert(A::count == 1);
assert(B::count == 0);
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
- {
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+ {
std::unique_ptr<A> p(new B);
assert(A::count == 1);
assert(B::count == 1);
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
- }
- assert(A::count == 0);
- assert(B::count == 0);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
}
#include <memory>
-struct A
-{
- std::unique_ptr<A> ptr_;
+struct A {
+ std::unique_ptr<A> ptr_;
- A() : ptr_(this) {}
- void reset() {ptr_.reset();}
+ A() : ptr_(this) {}
+ void reset() { ptr_.reset(); }
};
-int main()
-{
- (new A)->reset();
-}
+int main() { (new A)->reset(); }
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// test swap
+
+#include <memory>
+#include <cassert>
+
+#include "unique_ptr_test_helper.h"
+
+struct TT {
+ int state_;
+ static int count;
+ TT() : state_(-1) { ++count; }
+ explicit TT(int i) : state_(i) { ++count; }
+ TT(const TT& a) : state_(a.state_) { ++count; }
+ TT& operator=(const TT& a) {
+ state_ = a.state_;
+ return *this;
+ }
+ ~TT() { --count; }
+
+ friend bool operator==(const TT& x, const TT& y) {
+ return x.state_ == y.state_;
+ }
+};
+
+int TT::count = 0;
+
+template <class T>
+typename std::remove_all_extents<T>::type* newValueInit(int size,
+ int new_value) {
+ typedef typename std::remove_all_extents<T>::type VT;
+ VT* p = newValue<T>(size);
+ for (int i = 0; i < size; ++i)
+ (p + i)->state_ = new_value;
+ return p;
+}
+
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, TT[], TT>::type VT;
+ const int expect_alive = IsArray ? 5 : 1;
+ {
+ TT* p1 = newValueInit<VT>(expect_alive, 1);
+ std::unique_ptr<VT, Deleter<VT> > s1(p1, Deleter<VT>(1));
+ TT* p2 = newValueInit<VT>(expect_alive, 2);
+ std::unique_ptr<VT, Deleter<VT> > s2(p2, Deleter<VT>(2));
+ assert(s1.get() == p1);
+ assert(*s1.get() == TT(1));
+ assert(s1.get_deleter().state() == 1);
+ assert(s2.get() == p2);
+ assert(*s2.get() == TT(2));
+ assert(s2.get_deleter().state() == 2);
+ s1.swap(s2);
+ assert(s1.get() == p2);
+ assert(*s1.get() == TT(2));
+ assert(s1.get_deleter().state() == 2);
+ assert(s2.get() == p1);
+ assert(*s2.get() == TT(1));
+ assert(s2.get_deleter().state() == 1);
+ assert(TT::count == (expect_alive * 2));
+ }
+ assert(TT::count == 0);
+}
+
+int main() {
+ test_basic</*IsArray*/ false>();
+ test_basic<true>();
+}
#include <memory>
#include <cassert>
-int main()
-{
- {
- std::unique_ptr<int> p(new int(3));
- if (p)
- ;
- else
- assert(false);
- if (!p)
- assert(false);
- }
- {
- std::unique_ptr<int> p;
- if (!p)
- ;
- else
- assert(false);
- if (p)
- assert(false);
- }
+int main() {
+ std::unique_ptr<int[]> p(new int(3));
+ const std::unique_ptr<int[]>& cp = p;
+ (void)(*p); // expected-error {{indirection requires pointer operand ('std::unique_ptr<int []>' invalid)}}
+ (void)(*cp); // expected-error {{indirection requires pointer operand ('const std::unique_ptr<int []>' invalid)}}
}
#include <memory>
#include <cassert>
-int main()
-{
- std::unique_ptr<int> p(new int(3));
- assert(*p == 3);
+int main() {
+ std::unique_ptr<int> p(new int(3));
+ assert(*p == 3);
}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// test op*()
+
+#include <memory>
+#include <cassert>
+
+#include "test_macros.h"
+#include "unique_ptr_test_helper.h"
+
+template <class UPtr>
+void doTest(UPtr& p, bool ExpectTrue) {
+ if (p)
+ assert(ExpectTrue);
+ else
+ assert(!ExpectTrue);
+
+ if (!p)
+ assert(!ExpectTrue);
+ else
+ assert(ExpectTrue);
+}
+
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, int[], int>::type VT;
+ typedef std::unique_ptr<VT> U;
+ {
+ static_assert((std::is_constructible<bool, U>::value), "");
+ static_assert((std::is_constructible<bool, U const&>::value), "");
+ }
+#if TEST_STD_VER >= 11
+ {
+ static_assert(!std::is_convertible<U, bool>::value, "");
+ static_assert(!std::is_convertible<U const&, bool>::value, "");
+ }
+#endif
+ {
+ U p(newValue<VT>(1));
+ U const& cp = p;
+ doTest(p, true);
+ doTest(cp, true);
+ }
+ {
+ U p;
+ const U& cp = p;
+ doTest(p, false);
+ doTest(cp, false);
+ }
+}
+
+int main() {
+ test_basic</*IsArray*/ false>();
+ test_basic<true>();
+}
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// test get
+
+#include <memory>
+#include <cassert>
+
+#include "test_macros.h"
+#include "unique_ptr_test_helper.h"
+
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, int[], int>::type VT;
+ typedef const VT CVT;
+ {
+ typedef std::unique_ptr<VT> U;
+ int* p = newValue<VT>(1);
+ U s(p);
+ U const& sc = s;
+ ASSERT_SAME_TYPE(decltype(s.get()), int*);
+ ASSERT_SAME_TYPE(decltype(sc.get()), int*);
+ assert(s.get() == p);
+ assert(sc.get() == s.get());
+ }
+ {
+ typedef std::unique_ptr<CVT> U;
+ const int* p = newValue<VT>(1);
+ U s(p);
+ U const& sc = s;
+ ASSERT_SAME_TYPE(decltype(s.get()), const int*);
+ ASSERT_SAME_TYPE(decltype(sc.get()), const int*);
+ assert(s.get() == p);
+ assert(sc.get() == s.get());
+ }
+}
+
+int main() {
+ test_basic</*IsArray*/ false>();
+ test_basic<true>();
+}
int test() const { return 6; }
};
-int main() {
+template <bool IsArray>
+void test_basic() {
+ typedef typename std::conditional<IsArray, int[], int>::type VT;
{
std::unique_ptr<int, Deleter> p;
assert(p.get_deleter().test() == 5);
}
{
- const std::unique_ptr<int, Deleter> p;
+ const std::unique_ptr<VT, Deleter> p;
assert(p.get_deleter().test() == 6);
}
{
- typedef std::unique_ptr<int, const Deleter&> UPtr;
+ typedef std::unique_ptr<VT, const Deleter&> UPtr;
const Deleter d;
UPtr p(nullptr, d);
const UPtr& cp = p;
assert(cp.get_deleter().test() == 6);
}
{
- typedef std::unique_ptr<int, Deleter&> UPtr;
+ typedef std::unique_ptr<VT, Deleter&> UPtr;
Deleter d;
UPtr p(nullptr, d);
const UPtr& cp = p;
assert(cp.get_deleter().test() == 5);
}
}
+
+int main() {
+ test_basic</*IsArray*/ false>();
+ test_basic<true>();
+}
#include <memory>
#include <cassert>
-struct A
-{
- int i_;
-
- A() : i_(7) {}
+struct V {
+ int member;
};
-int main()
-{
- std::unique_ptr<A[]> p(new A);
- assert(p->i_ == 7);
+int main() {
+ std::unique_ptr<V[]> p;
+ std::unique_ptr<V[]> const& cp = p;
+
+ p->member; // expected-error {{member reference type 'std::unique_ptr<V []>' is not a pointer}}
+ // expected-error@-1 {{no member named 'member'}}
+
+ cp->member; // expected-error {{member reference type 'const std::unique_ptr<V []>' is not a pointer}}
+ // expected-error@-1 {{no member named 'member'}}
}
#include <memory>
#include <cassert>
-struct A
-{
- int i_;
+struct A {
+ int i_;
- A() : i_(7) {}
+ A() : i_(7) {}
};
-int main()
-{
- std::unique_ptr<A> p(new A);
- assert(p->i_ == 7);
+int main() {
+ std::unique_ptr<A> p(new A);
+ assert(p->i_ == 7);
}
#include <memory>
#include <cassert>
-class A
-{
- int state_;
- static int next_;
+class A {
+ int state_;
+ static int next_;
+
public:
- A() : state_(++next_) {}
- int get() const {return state_;}
+ A() : state_(++next_) {}
+ int get() const { return state_; }
- friend bool operator==(const A& x, int y)
- {return x.state_ == y;}
+ friend bool operator==(const A& x, int y) { return x.state_ == y; }
- A& operator=(int i) {state_ = i; return *this;}
+ A& operator=(int i) {
+ state_ = i;
+ return *this;
+ }
};
int A::next_ = 0;
-int main()
-{
- std::unique_ptr<A> p(new A[3]);
- assert(p[0] == 1);
- assert(p[1] == 2);
- assert(p[2] == 3);
- p[0] = 3;
- p[1] = 2;
- p[2] = 1;
- assert(p[0] == 3);
- assert(p[1] == 2);
- assert(p[2] == 1);
+int main() {
+ std::unique_ptr<A[]> p(new A[3]);
+ assert(p[0] == 1);
+ assert(p[1] == 2);
+ assert(p[2] == 3);
+ p[0] = 3;
+ p[1] = 2;
+ p[2] = 1;
+ assert(p[0] == 3);
+ assert(p[1] == 2);
+ assert(p[2] == 1);
}
// unique_ptr
-// test get
+// test op[](size_t)
#include <memory>
#include <cassert>
-int main()
-{
- int* p = new int[3];
- std::unique_ptr<int[]> s(p);
- assert(s.get() == p);
+int main() {
+ std::unique_ptr<int> p(new int[3]);
+ std::unique_ptr<int> const& cp = p;
+ p[0]; // expected-error {{type 'std::unique_ptr<int>' does not provide a subscript operator}}
+ cp[1]; // expected-error {{type 'const std::unique_ptr<int>' does not provide a subscript operator}}
}
# define TEST_WORKAROUND_C1XX_BROKEN_NULLPTR_CONVERSION_OPERATOR
#endif
+// FIXME(EricWF): Remove this. This macro guards tests for upcoming changes
+// and fixes to unique_ptr. Until the changes have been implemented in trunk
+// the tests have to be disabled. However the tests have been left in until
+// then so they can be used by other standard libraries.
+#if defined(_LIBCPP_VERSION)
+# define TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES
+#endif
+
#endif // SUPPORT_TEST_WORKAROUNDS_H
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEST_SUPPORT_UNIQUE_PTR_TEST_HELPER_H
+#define TEST_SUPPORT_UNIQUE_PTR_TEST_HELPER_H
+
+#include <memory>
+#include <type_traits>
+
+#include "test_macros.h"
+#include "deleter_types.h"
+
+struct A {
+ static int count;
+ A() { ++count; }
+ A(const A&) { ++count; }
+ virtual ~A() { --count; }
+};
+
+int A::count = 0;
+
+struct B : public A {
+ static int count;
+ B() { ++count; }
+ B(const B&) { ++count; }
+ virtual ~B() { --count; }
+};
+
+int B::count = 0;
+
+template <class T>
+typename std::enable_if<!std::is_array<T>::value, T*>::type
+newValue(int num_elements) {
+ assert(num_elements == 1);
+ return new T;
+}
+
+template <class T>
+typename std::enable_if<std::is_array<T>::value,
+ typename std::remove_all_extents<T>::type*>::type
+newValue(int num_elements) {
+ typedef typename std::remove_all_extents<T>::type VT;
+ assert(num_elements >= 1);
+ return new VT[num_elements];
+}
+
+struct IncompleteType;
+
+void checkNumIncompleteTypeAlive(int i);
+int getNumIncompleteTypeAlive();
+IncompleteType* getNewIncomplete();
+IncompleteType* getNewIncompleteArray(int size);
+
+#if TEST_STD_VER >= 11
+template <class ThisT, class ...Args>
+struct args_is_this_type : std::false_type {};
+
+template <class ThisT, class A1>
+struct args_is_this_type<ThisT, A1> : std::is_same<ThisT, typename std::decay<A1>::type> {};
+#endif
+
+template <class IncompleteT = IncompleteType,
+ class Del = std::default_delete<IncompleteT> >
+struct StoresIncomplete {
+ static_assert((std::is_same<IncompleteT, IncompleteType>::value ||
+ std::is_same<IncompleteT, IncompleteType[]>::value), "");
+
+ std::unique_ptr<IncompleteT, Del> m_ptr;
+
+#if TEST_STD_VER >= 11
+ StoresIncomplete(StoresIncomplete const&) = delete;
+ StoresIncomplete(StoresIncomplete&&) = default;
+
+ template <class ...Args>
+ StoresIncomplete(Args&&... args) : m_ptr(std::forward<Args>(args)...) {
+ static_assert(!args_is_this_type<StoresIncomplete, Args...>::value, "");
+ }
+#else
+private:
+ StoresIncomplete();
+ StoresIncomplete(StoresIncomplete const&);
+public:
+#endif
+
+ ~StoresIncomplete();
+
+ IncompleteType* get() const { return m_ptr.get(); }
+ Del& get_deleter() { return m_ptr.get_deleter(); }
+};
+
+#if TEST_STD_VER >= 11
+template <class IncompleteT = IncompleteType,
+ class Del = std::default_delete<IncompleteT>, class... Args>
+void doIncompleteTypeTest(int expect_alive, Args&&... ctor_args) {
+ using ValueT = typename std::remove_all_extents<IncompleteT>::type;
+
+
+ if (expect_alive == 0)
+ checkNumIncompleteTypeAlive(0);
+ else
+ checkNumIncompleteTypeAlive(expect_alive);
+
+ {
+ StoresIncomplete<IncompleteT, Del> sptr(std::forward<Args>(ctor_args)...);
+ checkNumIncompleteTypeAlive(expect_alive);
+ if (expect_alive == 0)
+ assert(sptr.get() == nullptr);
+ else
+ assert(sptr.get() != nullptr);
+ }
+ checkNumIncompleteTypeAlive(0);
+}
+#endif
+
+#define INCOMPLETE_TEST_EPILOGUE() \
+ int is_incomplete_test_anchor = is_incomplete_test(); \
+ \
+ struct IncompleteType { \
+ static int count; \
+ IncompleteType() { ++count; } \
+ ~IncompleteType() { --count; } \
+ }; \
+ \
+ int IncompleteType::count = 0; \
+ \
+ void checkNumIncompleteTypeAlive(int i) { \
+ assert(IncompleteType::count == i); \
+ } \
+ int getNumIncompleteTypeAlive() { return IncompleteType::count; } \
+ IncompleteType* getNewIncomplete() { return new IncompleteType; } \
+ IncompleteType* getNewIncompleteArray(int size) { \
+ return new IncompleteType[size]; \
+ } \
+ \
+ template <class IncompleteT, class Del> \
+ StoresIncomplete<IncompleteT, Del>::~StoresIncomplete() {}
+#
+
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wvariadic-macros"
+#endif
+
+#if TEST_STD_VER >= 11
+#define DEFINE_AND_RUN_IS_INCOMPLETE_TEST(...) \
+ static int is_incomplete_test() { __VA_ARGS__ return 0; } \
+ INCOMPLETE_TEST_EPILOGUE()
+#else
+#define DEFINE_AND_RUN_IS_INCOMPLETE_TEST(...) \
+ static int is_incomplete_test() { return 0; } \
+ INCOMPLETE_TEST_EPILOGUE()
+#endif
+
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+
+#endif // TEST_SUPPORT_UNIQUE_PTR_TEST_HELPER_H