[PATCH] D64671: [clang-tidy] New check: misc-init-local-variables

Jussi Pakkanen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 13 15:13:27 PDT 2019


jpakkane marked 10 inline comments as done.
jpakkane added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:26-29
+  if(!MatchedDecl->isLocalVarDecl())
+    return;
+  if(MatchedDecl->hasInit())
+    return;
----------------
lebedev.ri wrote:
> Can make these proper `AST_MATCHER` and do this in `registerMatchers()`.
Init checking is now in the matcher. I did not change isLocalVarDecl because according to the documentation there does not seem to be a builtin matcher for that. Since the isLocalVarDecl is semantically exactly what is needed here it seems a bit silly to reimplement that from scratch from matcher basic blocks.


================
Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:32-35
+  if(varName.empty() || varName.front() == '_') {
+    // Some standard library methods such as "be64toh" are implemented
+    // as macros that internally use variable names
+    // like __v. Do not touch those.
----------------
lebedev.ri wrote:
> This feels brittle.
> 
There's not much else one can do. Also, all variable names that begin with an underscore are reserved for the standard library (I think), so we should not be changing those in any case.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D64671





More information about the cfe-commits mailing list