[PATCH] D62829: [clang-tidy] Check for dynamically initialized statics in headers.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 9 09:03:50 PDT 2019


aaron.ballman added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp:39
+    return;
+  Finder->addMatcher(varDecl(hasGlobalStorage()).bind("var"), this);
+}
----------------
czhang wrote:
> aaron.ballman wrote:
> > Do you want to restrict this matcher to only variable declarations that have initializers, or are you also intending for this check to cover cases like:
> > ```
> > // At file scope.
> > struct S { S(); } s;
> > ```
> I think only variables with static storage are relevant to the stated goal of the checker.
Variables declared at file scope have static storage duration by default.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp:55
+  SourceLocation Loc = Var->getLocation();
+  if (!Loc.isValid() || !utils::isPresumedLocInHeaderFile(Loc, *Result.SourceManager,
+                                                          HeaderFileExtensions))
----------------
czhang wrote:
> aaron.ballman wrote:
> > We have an AST matcher for this (`isExpansionInSystemHeader()`).
> Isn't this for system headers only, not just included 'user' headers?
Ahh, good point! Still, this should be trivial to make a local AST matcher for.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62829/new/

https://reviews.llvm.org/D62829





More information about the cfe-commits mailing list