From: Richard Trieu Date: Wed, 29 Jul 2015 17:03:34 +0000 (+0000) Subject: Disable -Wpessimizing-move and -Wredundant-move in template instantiations. X-Git-Tag: studio-1.4~1298 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6093d143c5a76d168854321a1fc3d63e9c6d1ee6;p=platform%2Fupstream%2Fllvm.git Disable -Wpessimizing-move and -Wredundant-move in template instantiations. Dependent types can throw off the analysis for these warnings, possibly giving conflicting warnings and fix-its. Disabling the warning in template instantiations will prevent this problem, and will still catch the non-dependent cases in templates. llvm-svn: 243538 --- diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index fd06777..f66bc7f 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -5926,6 +5926,9 @@ static void CheckMoveOnConstruction(Sema &S, const Expr *InitExpr, if (!InitExpr) return; + if (!S.ActiveTemplateInstantiations.empty()) + return; + QualType DestType = InitExpr->getType(); if (!DestType->isRecordType()) return; diff --git a/clang/test/SemaCXX/warn-pessmizing-move.cpp b/clang/test/SemaCXX/warn-pessmizing-move.cpp index f5a4b90..5645564 100644 --- a/clang/test/SemaCXX/warn-pessmizing-move.cpp +++ b/clang/test/SemaCXX/warn-pessmizing-move.cpp @@ -196,3 +196,40 @@ A test10() { // expected-warning@-1{{prevents copy elision}} // CHECK-NOT: fix-it } + +namespace templates { + struct A {}; + struct B { B(A); }; + struct C { C(); C(C&&); }; + struct D { D(C); }; + + // Warn once here since the type is not dependent. + template + A test1() { + A a; + return std::move(a); + // expected-warning@-1{{prevents copy elision}} + // expected-note@-2{{remove std::move call}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:22}:"" + // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:"" + } + void run_test1() { + test1(); + test1(); + test1(); + test1(); + } + + // Either a pessimizing move, a redundant move, or no warning could be + // emitted, given the right types. So just drop the warning. + template + T1 test2() { + T2 t; + return std::move(t); + } + void run_test2() { + test2(); + test2(); + test2(); + } +} diff --git a/clang/test/SemaCXX/warn-redundant-move.cpp b/clang/test/SemaCXX/warn-redundant-move.cpp index 06f9c58..d160695 100644 --- a/clang/test/SemaCXX/warn-redundant-move.cpp +++ b/clang/test/SemaCXX/warn-redundant-move.cpp @@ -103,6 +103,43 @@ D test5(D d) { // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:21-[[@LINE-4]]:22}:"" } +namespace templates { + struct A {}; + struct B { B(A); }; + struct C { C(); C(C&&); }; + struct D { D(C); }; + + // Warn once here since the type is not dependent. + template + B test1() { + A a; + return std::move(a); + // expected-warning@-1{{redundant move in return statement}} + // expected-note@-2{{remove std::move call here}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:22}:"" + // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:"" + } + void run_test1() { + test1(); + test1(); + test1(); + test1(); + } + + // Either a pessimizing move, a redundant move, or no warning could be + // emitted, given the right types. So just drop the warning. + template + T1 test2() { + T2 t; + return std::move(t); + } + void run_test2() { + test2(); + test2(); + test2(); + } +} + // No more fix-its past here. // CHECK-NOT: fix-it