aboutsummaryrefslogtreecommitdiff
path: root/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp
blob: 24703ec98238e7c19a94c9aec26c7905199c678c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//===----------------------------------------------------------------------===//
//
//                     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
}