llvm-project
43 строки · 1.2 Кб
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -verify -fblocks -Wpessimizing-move -Wredundant-move %s
2
3// definitions for std::move
4namespace std {
5inline namespace foo {
6template <class T> struct remove_reference { typedef T type; };
7template <class T> struct remove_reference<T&> { typedef T type; };
8template <class T> struct remove_reference<T&&> { typedef T type; };
9
10template <class T> typename remove_reference<T>::type &&move(T &&t);
11}
12}
13
14class MoveOnly {
15public:
16MoveOnly() { }
17MoveOnly(MoveOnly &&) = default; // expected-note 2 {{copy constructor is implicitly deleted}}
18MoveOnly &operator=(MoveOnly &&) = default;
19~MoveOnly();
20};
21
22void copyInit() {
23__block MoveOnly temp;
24MoveOnly temp2 = temp; // expected-error {{call to implicitly-deleted copy constructor of 'MoveOnly'}}
25MoveOnly temp3 = std::move(temp); // ok
26}
27
28MoveOnly errorOnCopy() {
29__block MoveOnly temp;
30return temp; // expected-error {{call to implicitly-deleted copy constructor of 'MoveOnly'}}
31}
32
33MoveOnly dontWarnOnMove() {
34__block MoveOnly temp;
35return std::move(temp); // ok
36}
37
38class MoveOnlySub : public MoveOnly {};
39
40MoveOnly dontWarnOnMoveSubclass() {
41__block MoveOnlySub temp;
42return std::move(temp); // ok
43}
44