[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
Wed Dec 6 09:49:33 PST 2023


================
@@ -263,19 +264,26 @@ void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
 
 void UnnecessaryCopyInitialization::check(
     const MatchFinder::MatchResult &Result) {
-  const auto *NewVar = Result.Nodes.getNodeAs<VarDecl>("newVarDecl");
+  const auto &NewVar = *Result.Nodes.getNodeAs<VarDecl>("newVarDecl");
+  const auto &BlockStmt = *Result.Nodes.getNodeAs<Stmt>("blockStmt");
+  const auto &VarDeclStmt = *Result.Nodes.getNodeAs<DeclStmt>("declStmt");
+  const CheckContext Context{
+      NewVar, BlockStmt, VarDeclStmt, *Result.Context,
+      // Do not propose fixes if the DeclStmt has multiple VarDecls or in
+      // macros since we cannot place them correctly.
+      /*IssueFix*/ VarDeclStmt.isSingleDecl() &&
----------------
PiotrZSL wrote:

Do not call functions in this initialization, simple create local variables IssueFix, IsVarUnused, IsVarOnlyUsedAsConst and pass them to Context. In such case Context construction will be a simple one liner.

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


More information about the cfe-commits mailing list