[llvm-branch-commits] [clang-tools-extra] cc8df4d - [clang-tidy] Fix performance-move-const-arg for trivially copyable types with private copy constructor (#175449)

Cullen Rhodes via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 15 11:48:50 PST 2026


Author: mitchell
Date: 2026-01-15T19:48:41Z
New Revision: cc8df4d6a76fde3241e0a6563dc2c3d4905a6398

URL: https://github.com/llvm/llvm-project/commit/cc8df4d6a76fde3241e0a6563dc2c3d4905a6398
DIFF: https://github.com/llvm/llvm-project/commit/cc8df4d6a76fde3241e0a6563dc2c3d4905a6398.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 7747c5d0e96a7..186aa4cad2c8d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -664,6 +664,10 @@ Changes in existing checks
   <clang-tidy/checks/modernize/use-using>` check to correctly provide fix-its
   for typedefs of pointers or references to array types.
 
+- 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.
+
 - Improved :doc:`performance-unnecessary-copy-initialization
   <clang-tidy/checks/performance/unnecessary-copy-initialization>` by printing
   the type of the diagnosed variable.

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


        


More information about the llvm-branch-commits mailing list