[PATCH] D138655: [clang-tidy] Fix `cppcoreguidelines-init-variables` for invalid vardecl
gehry via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 24 23:34:54 PST 2022
Sockke updated this revision to Diff 477861.
Sockke added a comment.
Added test.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138655/new/
https://reviews.llvm.org/D138655
Files:
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables-clang-diagnostic-error.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables-clang-diagnostic-error.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables-clang-diagnostic-error.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -fix-errors --
+
+#include "unknown.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:10: error: 'unknown.h' file not found [clang-diagnostic-error]
+
+namespace std {
+template <typename T>
+struct vector {
+ vector();
+};
+
+void test() {
+ int a;
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'a' is not initialized [cppcoreguidelines-init-variables]
+ // CHECK-FIXES: {{^}} int a = 0;{{$}}
+ std::vector<int> arr;
+}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
@@ -60,6 +60,8 @@
const ASTContext &Context = *Result.Context;
const SourceManager &Source = Context.getSourceManager();
+ if (MatchedDecl->isInvalidDecl())
+ return;
// We want to warn about cases where the type name
// comes from a macro like this:
//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138655.477861.patch
Type: text/x-patch
Size: 1372 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221125/9cf77566/attachment-0001.bin>
More information about the cfe-commits
mailing list