2015-04-29 09:52:17 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -Wredundant-move -std=c++11 -verify %s
|
2015-07-30 07:47:19 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -Wredundant-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -ast-dump | FileCheck %s --check-prefix=CHECK-AST
|
2015-04-29 09:52:17 +08:00
|
|
|
|
|
|
|
// definitions for std::move
|
|
|
|
namespace std {
|
|
|
|
inline namespace foo {
|
|
|
|
template <class T> struct remove_reference { typedef T type; };
|
|
|
|
template <class T> struct remove_reference<T&> { typedef T type; };
|
|
|
|
template <class T> struct remove_reference<T&&> { typedef T type; };
|
|
|
|
|
|
|
|
template <class T> typename remove_reference<T>::type &&move(T &&t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 07:47:19 +08:00
|
|
|
// test1 and test2 should not warn until after implementation of DR1579.
|
2015-04-29 09:52:17 +08:00
|
|
|
struct A {};
|
|
|
|
struct B : public A {};
|
|
|
|
|
|
|
|
A test1(B b1) {
|
|
|
|
B b2;
|
2015-05-19 03:54:08 +08:00
|
|
|
return b1;
|
|
|
|
return b2;
|
2015-04-29 09:52:17 +08:00
|
|
|
return std::move(b1);
|
|
|
|
return std::move(b2);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct C {
|
|
|
|
C() {}
|
|
|
|
C(A) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
C test2(A a1, B b1) {
|
|
|
|
A a2;
|
|
|
|
B b2;
|
|
|
|
|
|
|
|
return a1;
|
|
|
|
return a2;
|
|
|
|
return b1;
|
|
|
|
return b2;
|
|
|
|
|
|
|
|
return std::move(a1);
|
|
|
|
return std::move(a2);
|
|
|
|
return std::move(b1);
|
|
|
|
return std::move(b2);
|
|
|
|
}
|
2015-05-19 03:54:08 +08:00
|
|
|
|
|
|
|
// Copy of tests above with types changed to reference types.
|
|
|
|
A test3(B& b1) {
|
|
|
|
B& b2 = b1;
|
|
|
|
return b1;
|
|
|
|
return b2;
|
|
|
|
return std::move(b1);
|
|
|
|
return std::move(b2);
|
|
|
|
}
|
|
|
|
|
|
|
|
C test4(A& a1, B& b1) {
|
|
|
|
A& a2 = a1;
|
|
|
|
B& b2 = b1;
|
|
|
|
|
|
|
|
return a1;
|
|
|
|
return a2;
|
|
|
|
return b1;
|
|
|
|
return b2;
|
|
|
|
|
|
|
|
return std::move(a1);
|
|
|
|
return std::move(a2);
|
|
|
|
return std::move(b1);
|
|
|
|
return std::move(b2);
|
|
|
|
}
|
2015-07-18 09:15:19 +08:00
|
|
|
|
2015-07-22 07:38:30 +08:00
|
|
|
// PR23819, case 2
|
|
|
|
struct D {};
|
|
|
|
D test5(D d) {
|
|
|
|
return d;
|
2015-07-30 07:47:19 +08:00
|
|
|
// Verify the implicit move from the AST dump
|
|
|
|
// CHECK-AST: ReturnStmt{{.*}}line:[[@LINE-2]]
|
|
|
|
// CHECK-AST-NEXT: CXXConstructExpr{{.*}}struct D{{.*}}void (struct D &&)
|
|
|
|
// CHECK-AST-NEXT: ImplicitCastExpr
|
|
|
|
// CHECK-AST-NEXT: DeclRefExpr{{.*}}ParmVar{{.*}}'d'
|
2015-07-22 07:38:30 +08:00
|
|
|
|
|
|
|
return std::move(d);
|
|
|
|
// expected-warning@-1{{redundant move in return statement}}
|
|
|
|
// expected-note@-2{{remove std::move call here}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:21-[[@LINE-4]]:22}:""
|
|
|
|
}
|
2015-07-29 03:06:16 +08:00
|
|
|
|
2015-07-30 01:03:34 +08:00
|
|
|
namespace templates {
|
|
|
|
struct A {};
|
|
|
|
struct B { B(A); };
|
|
|
|
|
|
|
|
// Warn once here since the type is not dependent.
|
|
|
|
template <typename T>
|
2015-07-30 07:47:19 +08:00
|
|
|
A test1(A a) {
|
2015-07-30 01:03:34 +08:00
|
|
|
return std::move(a);
|
|
|
|
// expected-warning@-1{{redundant move in return statement}}
|
|
|
|
// expected-note@-2{{remove std::move call here}}
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:22}:""
|
|
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:""
|
|
|
|
}
|
|
|
|
void run_test1() {
|
2015-07-30 07:47:19 +08:00
|
|
|
test1<A>(A());
|
|
|
|
test1<B>(A());
|
2015-07-30 01:03:34 +08:00
|
|
|
}
|
|
|
|
|
2015-07-30 07:47:19 +08:00
|
|
|
// T1 and T2 may not be the same, the warning may not always apply.
|
2015-07-30 01:03:34 +08:00
|
|
|
template <typename T1, typename T2>
|
2015-07-30 07:47:19 +08:00
|
|
|
T1 test2(T2 t) {
|
2015-07-30 01:03:34 +08:00
|
|
|
return std::move(t);
|
|
|
|
}
|
|
|
|
void run_test2() {
|
2015-07-30 07:47:19 +08:00
|
|
|
test2<A, A>(A());
|
|
|
|
test2<B, A>(A());
|
2015-07-30 01:03:34 +08:00
|
|
|
}
|
|
|
|
}
|