]> granicus.if.org Git - clang/commitdiff
Merging r242600:
authorHans Wennborg <hans@hanshq.net>
Thu, 30 Jul 2015 01:50:41 +0000 (01:50 +0000)
committerHans Wennborg <hans@hanshq.net>
Thu, 30 Jul 2015 01:50:41 +0000 (01:50 +0000)
------------------------------------------------------------------------
r242600 | davide | 2015-07-17 18:15:19 -0700 (Fri, 17 Jul 2015) | 8 lines

[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

------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_37@243605 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/SemaCXX/warn-pessmizing-move.cpp
test/SemaCXX/warn-redundant-move.cpp

index d3a249eae326eed36d2559644f04c3d96bda9975..ed5696358481783c7d9fa28583f611aec7fe4935 100644 (file)
@@ -5986,6 +5986,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
index 6b49944f287813f667e3f1269cb372fe93b73315..f5a4b909466eab7389d5ba173df1f0dcea25e9ae 100644 (file)
@@ -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
index feb9e6f408d967144b1f3bf991a70d1ae7d19397..e7996618c09686fee9555d64cc2b7a5ea7a1ebaa 100644 (file)
@@ -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}}