[clang-tools-extra] [clang-tidy] Don't suggest removing [[maybe_unused]] variables in performance-unnecessary-copy-initialization (PR #244978)
David Meng via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 19:46:28 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>() &&
----------------
davidmenggx wrote:
Good point, i will split the check for `[[maybe_unused]]`
https://github.com/llvm/llvm-project/pull/244978
More information about the cfe-commits
mailing list