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

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 12 15:18:56 PDT 2019


lebedev.ri added a comment.

This certainly needs more tests: macros, `-x C`, ???



================
Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:26-29
+  if(!MatchedDecl->isLocalVarDecl())
+    return;
+  if(MatchedDecl->hasInit())
+    return;
----------------
Can make these proper `AST_MATCHER` and do this in `registerMatchers()`.


================
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.
----------------
This feels brittle.



================
Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:41-48
+    replacement = "=0";
+  } else if(typePtr->isFloatingType()) {
+    replacement = "=(0.0/0.0)"; // NaN without needing #includes
+  } else if(typePtr->isPointerType()) {
+    if(getLangOpts().CPlusPlus) {
+      replacement = "=nullptr";
+    } else {
----------------
should be `var = <init>;`


================
Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:43
+  } else if(typePtr->isFloatingType()) {
+    replacement = "=(0.0/0.0)"; // NaN without needing #includes
+  } else if(typePtr->isPointerType()) {
----------------
I'm pretty sure there's simple utility function that can insert include.


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