[PATCH] D105727: [clang-tidy] performance-unnecessary-copy-initialization: Disable structured bindings.

Felix Berger via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 12 06:56:10 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG187e050b33bb: [clang-tidy] performance-unnecessary-copy-initialization: Disable structured… (authored by flx).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105727/new/

https://reviews.llvm.org/D105727

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
+// RUN: %check_clang_tidy -std=c++17 %s performance-unnecessary-copy-initialization %t
 
 template <typename T>
 struct Iterator {
@@ -637,3 +637,18 @@
     }
   };
 }
+
+void negativeStructuredBinding() {
+  // Structured bindings are not yet supported but can trigger false positives
+  // since the DecompositionDecl itself is unused and the check doesn't traverse
+  // VarDecls of the BindingDecls.
+  struct Pair {
+    ExpensiveToCopyType first;
+    ExpensiveToCopyType second;
+  };
+
+  Pair P;
+  const auto [C, D] = P;
+  C.constMethod();
+  D.constMethod();
+}
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===================================================================
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -147,6 +147,7 @@
     return compoundStmt(
                forEachDescendant(
                    declStmt(
+                       unless(has(decompositionDecl())),
                        has(varDecl(hasLocalStorage(),
                                    hasType(qualType(
                                        hasCanonicalType(allOf(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105727.357932.patch
Type: text/x-patch
Size: 1674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210712/c580e8d1/attachment.bin>


More information about the cfe-commits mailing list