[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 5 10:27:37 PST 2023


================
@@ -32,14 +32,34 @@ class UnnecessaryCopyInitialization : public ClangTidyCheck {
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
 
+protected:
+  // A helper to manipulate the state common to
+  // `CopyFromMethodReturn` and `CopyFromLocalVar`.
+  struct CheckContext {
+    CheckContext(const ast_matchers::MatchFinder::MatchResult &Result);
+    const VarDecl &Var;
+    const Stmt &BlockStmt;
+    const DeclStmt &VarDeclStmt;
+    clang::ASTContext &ASTCtx;
+    const bool IssueFix;
+    const bool IsVarUnused;
+    const bool IsVarOnlyUsedAsConst;
+  };
+
+  // Create diagnostics. These are virtual so that derived classes can change
+  // behaviour.
+  virtual void diagnoseCopyFromMethodReturn(const CheckContext &Ctx,
----------------
PiotrZSL wrote:

do not mix references with pointers, stick to one, specially in functions that does similar thing

https://github.com/llvm/llvm-project/pull/73921


More information about the cfe-commits mailing list