File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,10 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
59
59
const ASTContext &Context = *Result.Context ;
60
60
const SourceManager &Source = Context.getSourceManager ();
61
61
62
+ // Clang diagnostic error may cause the variable to be an invalid int vardecl
63
+ if (MatchedDecl->isInvalidDecl ())
64
+ return ;
65
+
62
66
// We want to warn about cases where the type name
63
67
// comes from a macro like this:
64
68
//
Original file line number Diff line number Diff line change 1
- // RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-delayed-template-parsing -fexceptions
1
+ // RUN: %check_clang_tidy %s cppcoreguidelines-init-variables -fix-errors %t -- -- -fno-delayed-template-parsing -fexceptions
2
2
// CHECK-FIXES: {{^}}#include <math.h>
3
3
4
4
// Ensure that function declarations are not changed.
@@ -124,3 +124,13 @@ void uninitialized_enum() {
124
124
Fruit fruit;
125
125
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'fruit' is not initialized [cppcoreguidelines-init-variables]
126
126
}
127
+
128
+ void test_clang_diagnostic_error () {
129
+ int a;
130
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'a' is not initialized [cppcoreguidelines-init-variables]
131
+ // CHECK-FIXES: {{^}} int a = 0;{{$}}
132
+
133
+ UnknownType b;
134
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: error: unknown type name 'UnknownType' [clang-diagnostic-error]
135
+ // CHECK-FIXES-NOT: {{^}} UnknownType b = 0;{{$}}
136
+ }
You can’t perform that action at this time.
0 commit comments