Author: rtrieu Date: Wed Jul 29 12:03:34 2015 New Revision: 243538 URL: http://llvm.org/viewvc/llvm-project?rev=243538&view=rev Log: 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. Modified: cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/test/SemaCXX/warn-pessmizing-move.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=243538&r1=243537&r2=243538&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaInit.cpp (original) +++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Jul 29 12:03:34 2015 @@ -5926,6 +5926,9 @@ static void CheckMoveOnConstruction(Sema if (!InitExpr) return; + if (!S.ActiveTemplateInstantiations.empty()) + return; + QualType DestType = InitExpr->getType(); if (!DestType->isRecordType()) return; Modified: cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp?rev=243538&r1=243537&r2=243538&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-pessmizing-move.cpp Wed Jul 29 12:03:34 2015 @@ -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 <typename T> + 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<A>(); + test1<B>(); + test1<C>(); + test1<D>(); + } + + // Either a pessimizing move, a redundant move, or no warning could be + // emitted, given the right types. So just drop the warning. + template <typename T1, typename T2> + T1 test2() { + T2 t; + return std::move(t); + } + void run_test2() { + test2<A, A>(); + test2<B, A>(); + test2<D, C>(); + } +} 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=243538&r1=243537&r2=243538&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/warn-redundant-move.cpp (original) +++ cfe/trunk/test/SemaCXX/warn-redundant-move.cpp Wed Jul 29 12:03:34 2015 @@ -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 <typename T> + 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<A>(); + test1<B>(); + test1<C>(); + test1<D>(); + } + + // Either a pessimizing move, a redundant move, or no warning could be + // emitted, given the right types. So just drop the warning. + template <typename T1, typename T2> + T1 test2() { + T2 t; + return std::move(t); + } + void run_test2() { + test2<A, A>(); + test2<B, A>(); + test2<D, C>(); + } +} + // No more fix-its past here. // CHECK-NOT: fix-it _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits