[PATCH] D138655: [clang-tidy] Fix `cppcoreguidelines-init-variables` for invalid vardecl

gehry via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 24 04:19:33 PST 2022


Sockke created this revision.
Sockke added a reviewer: aaron.ballman.
Herald added subscribers: carlosgalvezp, shchenz, kbarton, xazax.hun, nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
Sockke requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

https://godbolt.org/z/n4cK4fo3o
The checker missed a check for invalid vardecl and this could cause a false positive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138655

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp


Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -60,6 +60,8 @@
   const ASTContext &Context = *Result.Context;
   const SourceManager &Source = Context.getSourceManager();
 
+  if (MatchedDecl->isInvalidDecl())
+    return;
   // We want to warn about cases where the type name
   // comes from a macro like this:
   //


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138655.477740.patch
Type: text/x-patch
Size: 568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221124/b304632e/attachment.bin>


More information about the cfe-commits mailing list