r237607 - Have -Wredundant-move ignore reference types.

Richard Trieu rtrieu at google.com
Mon May 18 12:54:08 PDT 2015


Author: rtrieu
Date: Mon May 18 14:54:08 2015
New Revision: 237607

URL: http://llvm.org/viewvc/llvm-project?rev=237607&view=rev
Log:
Have -Wredundant-move ignore reference types.

Don't give a warning when the type being moved is a reference type.  Also
uncomment two lines in the test case.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/warn-redundant-move.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=237607&r1=237606&r2=237607&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon May 18 14:54:08 2015
@@ -5831,6 +5831,9 @@ static void CheckMoveOnConstruction(Sema
     if (!VD || !VD->hasLocalStorage())
       return;
 
+    if (!VD->getType()->isRecordType())
+      return;
+
     if (DiagID == 0) {
       DiagID = S.Context.hasSameUnqualifiedType(DestType, VD->getType())
                    ? diag::warn_pessimizing_move_on_return

Modified: cfe/trunk/test/SemaCXX/warn-redundant-move.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-redundant-move.cpp?rev=237607&r1=237606&r2=237607&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-redundant-move.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-redundant-move.cpp Mon May 18 14:54:08 2015
@@ -17,8 +17,8 @@ struct B : public A {};
 
 A test1(B b1) {
   B b2;
-  //return b1;
-  //return b2;
+  return b1;
+  return b2;
   return std::move(b1);
   // expected-warning at -1{{redundant move}}
   // expected-note at -2{{remove std::move call}}
@@ -66,3 +66,27 @@ C test2(A a1, B b1) {
   // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:22-[[@LINE-4]]:23}:""
 }
+
+// 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);
+}





More information about the cfe-commits mailing list