madsravn created this revision. madsravn added reviewers: alexfh, vsk, djasper, klimek. madsravn added a subscriber: cfe-commits.
This is a patch for bug: https://llvm.org/bugs/show_bug.cgi?id=27731 I have excluded types which are trivially copyable from being called with std::move in the modernizer. In the current state another modernizer will catch them and change them back, thus creating a cyclic behaviour. http://reviews.llvm.org/D20365 Files: clang-tidy/modernize/PassByValueCheck.cpp test/clang-tidy/modernize-pass-by-value.cpp Index: test/clang-tidy/modernize-pass-by-value.cpp =================================================================== --- test/clang-tidy/modernize-pass-by-value.cpp +++ test/clang-tidy/modernize-pass-by-value.cpp @@ -194,3 +194,9 @@ Movable M; }; +// Test that types that are trivially copyable will not use std::move. This will +// cause problems with misc-move-const-arg, as it will revert it. +struct T { + std::array<int, 10> a_; + T(std::array<int, 10> a) : a_(a) {} +}; Index: clang-tidy/modernize/PassByValueCheck.cpp =================================================================== --- clang-tidy/modernize/PassByValueCheck.cpp +++ clang-tidy/modernize/PassByValueCheck.cpp @@ -181,6 +181,11 @@ if (!paramReferredExactlyOnce(Ctor, ParamDecl)) return; + // If the parameter is trivial to copy, don't move it. Moving a trivivally + // copyable type will cause a problem with modernize-pass-by-value + if (ParamDecl->getType().isTriviallyCopyableType(*Result.Context)) + return; + auto Diag = diag(ParamDecl->getLocStart(), "pass by value and use std::move"); // Iterate over all declarations of the constructor.
Index: test/clang-tidy/modernize-pass-by-value.cpp =================================================================== --- test/clang-tidy/modernize-pass-by-value.cpp +++ test/clang-tidy/modernize-pass-by-value.cpp @@ -194,3 +194,9 @@ Movable M; }; +// Test that types that are trivially copyable will not use std::move. This will +// cause problems with misc-move-const-arg, as it will revert it. +struct T { + std::array<int, 10> a_; + T(std::array<int, 10> a) : a_(a) {} +}; Index: clang-tidy/modernize/PassByValueCheck.cpp =================================================================== --- clang-tidy/modernize/PassByValueCheck.cpp +++ clang-tidy/modernize/PassByValueCheck.cpp @@ -181,6 +181,11 @@ if (!paramReferredExactlyOnce(Ctor, ParamDecl)) return; + // If the parameter is trivial to copy, don't move it. Moving a trivivally + // copyable type will cause a problem with modernize-pass-by-value + if (ParamDecl->getType().isTriviallyCopyableType(*Result.Context)) + return; + auto Diag = diag(ParamDecl->getLocStart(), "pass by value and use std::move"); // Iterate over all declarations of the constructor.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits