]> granicus.if.org Git - clang/commitdiff
Have -Wredundant-move ignore reference types.
authorRichard Trieu <rtrieu@google.com>
Mon, 18 May 2015 19:54:08 +0000 (19:54 +0000)
committerRichard Trieu <rtrieu@google.com>
Mon, 18 May 2015 19:54:08 +0000 (19:54 +0000)
Don't give a warning when the type being moved is a reference type.  Also
uncomment two lines in the test case.

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

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

index 7dd93e8de5891fadf5d9effa4ceaedff224b5f46..610e0a9a038970e0f236c2f8079d46517c8e34dc 100644 (file)
@@ -5831,6 +5831,9 @@ static void CheckMoveOnConstruction(Sema &S, const Expr *InitExpr,
     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
index 8469d4fa53da716d870691ad9e73ed51e4850198..feb9e6f408d967144b1f3bf991a70d1ae7d19397 100644 (file)
@@ -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@-1{{redundant move}}
   // expected-note@-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);
+}