diff options
-rw-r--r-- | clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp | 6 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/modernize-pass-by-value.cpp | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp index c727deb7969..31a1d96320e 100644 --- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp @@ -181,6 +181,12 @@ void PassByValueCheck::check(const MatchFinder::MatchResult &Result) { 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. diff --git a/clang-tools-extra/test/clang-tidy/modernize-pass-by-value.cpp b/clang-tools-extra/test/clang-tidy/modernize-pass-by-value.cpp index f981bf3f1fc..e4c97317b3f 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-pass-by-value.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-pass-by-value.cpp @@ -194,3 +194,9 @@ struct S { 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) {} +}; |