[clang-tools-extra] [clang-tidy] fix false positives when using name-independent variables after C++26 for bugprone-unused-local-non-trivial-variable (PR #121783)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 8 12:46:22 PST 2025


================
@@ -29,6 +29,12 @@ static constexpr StringRef DefaultIncludeTypeRegex =
 
 AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
 AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
+AST_MATCHER_P(VarDecl, explicitMarkUnused, LangOptions, LangOpts) {
+  // Implementations should not emit a warning that a name-independent
+  // declaration is used or unused.
+  return Node.hasAttr<UnusedAttr>() ||
+         (LangOpts.CPlusPlus26 && Node.isPlaceholderVar(LangOpts));
----------------
PiotrZSL wrote:

And, you dont need to pass LangOptions via argument.
>From matcher you got access to ASTContext, and that class got [getLangOpts](https://clang.llvm.org/doxygen/classclang_1_1ASTContext.html#a50f31d935973dd09016088579ba81944)

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


More information about the cfe-commits mailing list