[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)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 8 13:16:45 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));
----------------
HerrCai0907 wrote:

> Out of curiosity, is the CplusPlus26 needed? Won't isPlaceholderVar return false otherwise?

Yes, `isPlaceholderVar` does not check cpp version.

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


More information about the cfe-commits mailing list