[PATCH] D11305: [Sema] Emit correct warning when copy-elision is not possible.
Davide Italiano
dccitaliano at gmail.com
Fri Jul 17 18:15:38 PDT 2015
This revision was automatically updated to reflect the committed changes.
davide marked an inline comment as done.
Closed by commit rL242600: [Sema] Emit correct warning when copy-elision is not possible. (authored by davide).
Changed prior to commit:
http://reviews.llvm.org/D11305?vs=30031&id=30061#toc
Repository:
rL LLVM
http://reviews.llvm.org/D11305
Files:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp
cfe/trunk/test/SemaCXX/warn-redundant-move.cpp
Index: cfe/trunk/test/SemaCXX/warn-redundant-move.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/warn-redundant-move.cpp
+++ cfe/trunk/test/SemaCXX/warn-redundant-move.cpp
@@ -90,3 +90,10 @@
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}}
Index: cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp
+++ cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp
@@ -23,10 +23,6 @@
return a1;
return a2;
return std::move(a1);
- // expected-warning at -1{{prevents copy elision}}
- // expected-note at -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 at -1{{prevents copy elision}}
// expected-note at -2{{remove std::move call}}
@@ -46,10 +42,6 @@
return b1;
return b2;
return std::move(b1);
- // expected-warning at -1{{prevents copy elision}}
- // expected-note at -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 at -1{{prevents copy elision}}
// expected-note at -2{{remove std::move call}}
@@ -163,9 +155,10 @@
#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 at -1{{prevents copy elision}}
// expected-note at -2{{remove std::move call}}
@@ -184,7 +177,8 @@
}
#define test9 \
- A test9(A a) { \
+ A test9() { \
+ A a; \
return std::move(a); \
}
@@ -196,7 +190,8 @@
#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 at -1{{prevents copy elision}}
// CHECK-NOT: fix-it
Index: cfe/trunk/lib/Sema/SemaInit.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp
+++ cfe/trunk/lib/Sema/SemaInit.cpp
@@ -5988,6 +5988,11 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11305.30061.patch
Type: text/x-patch
Size: 3014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150718/58b6500d/attachment.bin>
More information about the cfe-commits
mailing list