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

Carlos Galvez via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 19 02:56:41 PST 2022


carlosgalvezp added a comment.

Looks good in general, IMHO it would be good with a couple more comments to make the code and test easier to understand.



================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp:63
 
+  if (MatchedDecl->isInvalidDecl())
+    return;
----------------
Add a comment as to why this is needed? I haven't seen this pattern often in checks.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp:4
 
+#include "unknown.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:10: error: 'unknown.h' file not found [clang-diagnostic-error]
----------------
Add a comment explaining the purpose of introducing this error? At first sight, it's not obvious to me why this is needed.



================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp:141
+  // CHECK-FIXES: {{^}}  int a = 0;{{$}}
+  std::vector<int> arr;
+}
----------------
Perhaps add a comment explaining that clang-tidy should not warn here, and why.


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

https://reviews.llvm.org/D138655



More information about the cfe-commits mailing list