Sockke updated this revision to Diff 478529. Sockke added a comment. Added test in existing `init-variables.cpp` file.
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.cpp Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp +++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp @@ -1,6 +1,15 @@ -// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-delayed-template-parsing -fexceptions +// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables -fix-errors %t -- -- -fno-delayed-template-parsing -fexceptions // CHECK-FIXES: {{^}}#include <math.h> +#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(); +}; + // Ensure that function declarations are not changed. void some_func(int x, double d, bool b, const char *p); @@ -124,3 +133,10 @@ Fruit fruit; // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'fruit' is not initialized [cppcoreguidelines-init-variables] } + +void test_clang_diagnostic_error() { + 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: //
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp +++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp @@ -1,6 +1,15 @@ -// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- -fno-delayed-template-parsing -fexceptions +// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables -fix-errors %t -- -- -fno-delayed-template-parsing -fexceptions // CHECK-FIXES: {{^}}#include <math.h> +#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(); +}; + // Ensure that function declarations are not changed. void some_func(int x, double d, bool b, const char *p); @@ -124,3 +133,10 @@ Fruit fruit; // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'fruit' is not initialized [cppcoreguidelines-init-variables] } + +void test_clang_diagnostic_error() { + 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: //
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits