1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
7 unique_ptr(const unique_ptr
&) = delete; // expected-note 3{{'unique_ptr' has been explicitly marked deleted here}}
8 unique_ptr
&operator=(const unique_ptr
&) = delete; // expected-note{{candidate function has been explicitly deleted}}
10 unique_ptr() : ptr(0) { }
11 unique_ptr(unique_ptr
&&other
) : ptr(other
.ptr
) { other
.ptr
= 0; }
12 explicit unique_ptr(T
*ptr
) : ptr(ptr
) { }
14 ~unique_ptr() { delete ptr
; }
16 unique_ptr
&operator=(unique_ptr
&&other
) { // expected-note{{candidate function not viable: expects an rvalue for 1st argument}}
28 struct remove_reference
{
33 struct remove_reference
<T
&> {
38 struct remove_reference
<T
&&> {
43 template <class T
> typename remove_reference
<T
>::type
&& move(T
&& t
) {
44 return static_cast<typename remove_reference
<T
>::type
&&>(t
);
47 template <class T
> T
&& forward(typename remove_reference
<T
>::type
& t
) {
48 return static_cast<T
&&>(t
);
51 template <class T
> T
&& forward(typename remove_reference
<T
>::type
&& t
) {
52 return static_cast<T
&&>(t
);
55 template<typename T
, typename
...Args
>
56 unique_ptr
<T
> make_unique_ptr(Args
&&...args
) {
57 return unique_ptr
<T
>(new T(forward
<Args
>(args
)...));
60 template<typename T
> void accept_unique_ptr(unique_ptr
<T
>); // expected-note{{passing argument to parameter here}}
62 unique_ptr
<int> test_unique_ptr() {
63 // Simple construction
65 unique_ptr
<int> p1(new int);
68 unique_ptr
<int> p2(make_unique_ptr
<int>(17));
69 unique_ptr
<int> p3
= make_unique_ptr
<int>(17);
71 // Copy construction (failures)
72 unique_ptr
<int> p4(p
); // expected-error{{call to deleted constructor of 'unique_ptr<int>'}}
73 unique_ptr
<int> p5
= p
; // expected-error{{call to deleted constructor of 'unique_ptr<int>'}}
77 p2
= make_unique_ptr
<int>(0);
79 // Copy assignment (failures);
80 p2
= p3
; // expected-error{{overload resolution selected deleted operator '='}}
83 accept_unique_ptr(make_unique_ptr
<double>(0.0));
84 accept_unique_ptr(move(p2
));
86 // Implicit copies (failures);
87 accept_unique_ptr(p
); // expected-error{{call to deleted constructor of 'unique_ptr<int>'}}
92 namespace perfect_forwarding
{
96 void operator()(A
&, const A
&, A
&&, const A
&&, A
&&, const A
&&); // expected-note{{candidate function not viable: 5th argument ('const perfect_forwarding::A') would lose const qualifier}}
99 template<typename F
, typename
...Args
>
100 void forward(F f
, Args
&&...args
) {
101 f(static_cast<Args
&&>(args
)...); // expected-error{{no matching function for call to object of type 'perfect_forwarding::F0'}}
104 template<typename T
> T
get();
106 void test_forward() {
107 forward(F0(), get
<A
&>(), get
<A
const&>(), get
<A
>(), get
<const A
>(),
108 get
<A
&&>(), get
<const A
&&>());
109 forward(F0(), get
<A
&>(), get
<A
const&>(), get
<A
>(), get
<const A
>(), // expected-note{{in instantiation of function template specialization 'perfect_forwarding::forward<perfect_forwarding::F0, perfect_forwarding::A &, const perfect_forwarding::A &, perfect_forwarding::A, const perfect_forwarding::A, const perfect_forwarding::A, const perfect_forwarding::A>' requested here}}
110 get
<const A
&&>(), get
<const A
&&>());