Author: mitchell Date: 2026-01-15T23:13:14+08:00 New Revision: 513062dd583dc65e29987f3716f5b6fa9c1b4fe9
URL: https://github.com/llvm/llvm-project/commit/513062dd583dc65e29987f3716f5b6fa9c1b4fe9 DIFF: https://github.com/llvm/llvm-project/commit/513062dd583dc65e29987f3716f5b6fa9c1b4fe9.diff LOG: [clang-tidy] Fix performance-move-const-arg for trivially copyable types with private copy constructor (#175449) Closes [#174826](https://github.com/llvm/llvm-project/issues/174826) Added: Modified: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp index 91f025dc87d8e..63be104df5e05 100644 --- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp @@ -136,7 +136,8 @@ void MoveConstArgCheck::check(const MatchFinder::MatchResult &Result) { return; // Don't warn when the type is not copyable. for (const auto *Ctor : R->ctors()) - if (Ctor->isCopyConstructor() && Ctor->isDeleted()) + if (Ctor->isCopyConstructor() && + (Ctor->isDeleted() || Ctor->getAccess() != AS_public)) return; } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 69c3bcf67b8db..54f5eed5306e4 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -94,6 +94,10 @@ Improvements to clang-query Improvements to clang-tidy -------------------------- +- Improved :doc:`performance-move-const-arg + <clang-tidy/checks/performance/move-const-arg>` check by avoiding false + positives on trivially copyable types with a non-public copy constructor. + New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp index e616cbe78bc3a..34d51930ac6c8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp @@ -583,3 +583,37 @@ void testTernaryMove() { }; } // namespace GH126515 + +namespace GH174826 { + +struct PrivateCopy { + PrivateCopy() = default; + PrivateCopy(PrivateCopy &&) = default; + +private: + PrivateCopy(const PrivateCopy &) = default; +}; + +void receive(PrivateCopy) {} + +void testPrivate() { + PrivateCopy v; + receive(std::move(v)); +} + +struct PublicCopy { + PublicCopy() = default; + PublicCopy(const PublicCopy &) = default; + PublicCopy(PublicCopy &&) = default; +}; + +void receive(PublicCopy) {} + +void testPublic() { + PublicCopy v; + receive(std::move(v)); + // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: std::move of the variable 'v' of the trivially-copyable type 'PublicCopy' has no effect; remove std::move() [performance-move-const-arg] + // CHECK-FIXES: receive(v); +} + +} // namespace GH174826 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
