[clang-tools-extra] [clang-tidy] Don't suggest removing [[maybe_unused]] variables in performance-unnecessary-copy-initialization (PR #244978)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 19:02:02 PST 2026


================
@@ -182,7 +182,10 @@ static bool isInitializingVariableImmutable(
 
 static bool isVariableUnused(const VarDecl &Var, const Stmt &BlockStmt,
                              ASTContext &Context) {
-  return allDeclRefExprs(Var, BlockStmt, Context).empty();
+  // A variable marked `[[maybe_unused]]` should not be treated as unused.
+  // Suggest a const reference instead.
+  return !Var.hasAttr<UnusedAttr>() &&
----------------
zeyi2 wrote:

Nit: If I understand this correctly, `isVariableUnused()` now no longer checks whether the variable is actually unused? A variable marked `[[maybe_unused]]` may still have no references.

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


More information about the cfe-commits mailing list