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

Jussi Pakkanen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 09:50:41 PDT 2019


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


================
Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:21
+  Finder->addMatcher(
+      varDecl(unless(hasInitializer(anything()))).bind("vardecl"), this);
+}
----------------
alexfh wrote:
> I believe, this should skip matches within template instantiations. Consider this code:
> ```
> template<typename T>
> void f(T) { T t; }
> void g() {
>     f(0);
>     f(0.0);
> }
> ```
> 
> What will the fix  be?
I tested with the following function:


```
template<typename T>
void template_test_function() {
  T t;
  int uninitialized;
}
```

Currently it warns on the "uninitialized" variable regardless of whether the template is instantiated or not. If you call it with an int type, it will warn about variable t being uninitialized. If you call it with a, say, struct type, there is no warnings. Is this a reasonable approach?


================
Comment at: clang-tools-extra/clang-tidy/misc/InitLocalVariablesCheck.cpp:32
+  StringRef VarName = MatchedDecl->getName();
+  if (VarName.empty() || VarName.front() == '_') {
+    // Some standard library methods such as "be64toh" are implemented
----------------
alexfh wrote:
> Should this just disallow all fixes within macros? Maybe warnings as well.
I can change that, seems reasonable. Should it still retain this check, though? One would imagine there are other ways of getting variables whose names begin with an underscore.


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