summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2015-07-18 01:15:19 +0000
committerDavide Italiano <davide@freebsd.org>2015-07-18 01:15:19 +0000
commit7842c3fceadaa1fcef7c91c59d822a572a17c8e2 (patch)
treee55503b0d4c4565f6d80c814b93ccd568e9803bd /clang
parent857a43c70a95efbb76b5d90e38e166cf802507a5 (diff)
downloadbcm5719-llvm-7842c3fceadaa1fcef7c91c59d822a572a17c8e2.tar.gz
bcm5719-llvm-7842c3fceadaa1fcef7c91c59d822a572a17c8e2.zip
[Sema] Emit correct warning when copy-elision is not possible.
If we're returning a function parameter, copy elision isn't possible, so we now warn for redundant move. PR: 23819 Differential Revision: http://reviews.llvm.org/D11305 llvm-svn: 242600
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaInit.cpp5
-rw-r--r--clang/test/SemaCXX/warn-pessmizing-move.cpp19
-rw-r--r--clang/test/SemaCXX/warn-redundant-move.cpp7
3 files changed, 19 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index f0f7cb93d33..25d091f1d8c 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5988,6 +5988,11 @@ static void CheckMoveOnConstruction(Sema &S, const Expr *InitExpr,
if (!VD->getType()->isRecordType())
return;
+ // If we're returning a function parameter, copy elision
+ // is not possible.
+ if (isa<ParmVarDecl>(VD))
+ DiagID = diag::warn_redundant_move_on_return;
+
if (DiagID == 0) {
DiagID = S.Context.hasSameUnqualifiedType(DestType, VD->getType())
? diag::warn_pessimizing_move_on_return
diff --git a/clang/test/SemaCXX/warn-pessmizing-move.cpp b/clang/test/SemaCXX/warn-pessmizing-move.cpp
index 6b49944f287..f5a4b909466 100644
--- a/clang/test/SemaCXX/warn-pessmizing-move.cpp
+++ b/clang/test/SemaCXX/warn-pessmizing-move.cpp
@@ -23,10 +23,6 @@ A test1(A a1) {
return a1;
return a2;
return std::move(a1);
- // expected-warning@-1{{prevents copy elision}}
- // expected-note@-2{{remove std::move call}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
- // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:23}:""
return std::move(a2);
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
@@ -46,10 +42,6 @@ B test2(A a1, B b1) {
return b1;
return b2;
return std::move(b1);
- // expected-warning@-1{{prevents copy elision}}
- // expected-note@-2{{remove std::move call}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
- // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:23}:""
return std::move(b2);
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
@@ -163,9 +155,10 @@ A test7() {
#define wrap1(x) x
#define wrap2(x) x
-// Macro test. Since the std::move call is outside the macro, it is
+// Macro test. Since the std::move call is outside the macro, it is
// safe to suggest a fix-it.
-A test8(A a) {
+A test8() {
+ A a;
return std::move(a);
// expected-warning@-1{{prevents copy elision}}
// expected-note@-2{{remove std::move call}}
@@ -184,7 +177,8 @@ A test8(A a) {
}
#define test9 \
- A test9(A a) { \
+ A test9() { \
+ A a; \
return std::move(a); \
}
@@ -196,7 +190,8 @@ test9
#define return_a return std::move(a)
// Macro test. The std::call is inside the macro, so no fix-it is suggested.
-A test10(A a) {
+A test10() {
+ A a;
return_a;
// expected-warning@-1{{prevents copy elision}}
// CHECK-NOT: fix-it
diff --git a/clang/test/SemaCXX/warn-redundant-move.cpp b/clang/test/SemaCXX/warn-redundant-move.cpp
index feb9e6f408d..e7996618c09 100644
--- a/clang/test/SemaCXX/warn-redundant-move.cpp
+++ b/clang/test/SemaCXX/warn-redundant-move.cpp
@@ -90,3 +90,10 @@ C test4(A& a1, B& b1) {
return std::move(b1);
return std::move(b2);
}
+
+//PR23819
+struct X {};
+X g();
+void h(X&&);
+X f(X x) { return std::move(x); } //expected-warning{{redundant move in return statement}} \
+ //expected-note{{remove std::move call here}}
OpenPOWER on IntegriCloud