diff options
author | Jonathan Roelofs <jonathan@codesourcery.com> | 2016-01-13 17:36:41 +0000 |
---|---|---|
committer | Jonathan Roelofs <jonathan@codesourcery.com> | 2016-01-13 17:36:41 +0000 |
commit | f502328e6cf163245287d54694b089637ffdddfe (patch) | |
tree | 202a61141bb80ec801c5d7ecc0ec4bd81d87219d /clang-tidy/ClangTidy.cpp | |
parent | e2ddab9dc5484edc870fe8ff19c9762ef6373dba (diff) |
Teach clang-tidy how to upgrade warnings into errors.
Similar in format to the `-checks=` argument, this new `-warnings-as-errors=`
argument upgrades any warnings emitted by the former to errors.
http://reviews.llvm.org/D15528
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@257642 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/ClangTidy.cpp')
-rw-r--r-- | clang-tidy/ClangTidy.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/clang-tidy/ClangTidy.cpp b/clang-tidy/ClangTidy.cpp index 0b9895bc..66ab56a7 100644 --- a/clang-tidy/ClangTidy.cpp +++ b/clang-tidy/ClangTidy.cpp @@ -101,7 +101,8 @@ public: Diags(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts, DiagPrinter), SourceMgr(Diags, Files), Rewrite(SourceMgr, LangOpts), - ApplyFixes(ApplyFixes), TotalFixes(0), AppliedFixes(0) { + ApplyFixes(ApplyFixes), TotalFixes(0), AppliedFixes(0), + WarningsAsErrors(0) { DiagOpts->ShowColors = llvm::sys::Process::StandardOutHasColors(); DiagPrinter->BeginSourceFile(LangOpts); } @@ -114,8 +115,14 @@ public: SmallVector<std::pair<SourceLocation, bool>, 4> FixLocations; { auto Level = static_cast<DiagnosticsEngine::Level>(Error.DiagLevel); + std::string Name = Error.CheckName; + if (Error.IsWarningAsError) { + Name += ",-warnings-as-errors"; + Level = DiagnosticsEngine::Error; + WarningsAsErrors++; + } auto Diag = Diags.Report(Loc, Diags.getCustomDiagID(Level, "%0 [%1]")) - << Message.Message << Error.CheckName; + << Message.Message << Name; for (const tooling::Replacement &Fix : Error.Fix) { SourceLocation FixLoc = getLocation(Fix.getFilePath(), Fix.getOffset()); SourceLocation FixEndLoc = FixLoc.getLocWithOffset(Fix.getLength()); @@ -147,6 +154,8 @@ public: } } + unsigned getWarningsAsErrorsCount() const { return WarningsAsErrors; } + private: SourceLocation getLocation(StringRef FilePath, unsigned Offset) { if (FilePath.empty()) @@ -174,6 +183,7 @@ private: bool ApplyFixes; unsigned TotalFixes; unsigned AppliedFixes; + unsigned WarningsAsErrors; }; class ClangTidyASTConsumer : public MultiplexConsumer { @@ -421,11 +431,13 @@ runClangTidy(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider, return Context.getStats(); } -void handleErrors(const std::vector<ClangTidyError> &Errors, bool Fix) { +void handleErrors(const std::vector<ClangTidyError> &Errors, bool Fix, + unsigned &WarningsAsErrorsCount) { ErrorReporter Reporter(Fix); for (const ClangTidyError &Error : Errors) Reporter.reportDiagnostic(Error); Reporter.Finish(); + WarningsAsErrorsCount += Reporter.getWarningsAsErrorsCount(); } void exportReplacements(const std::vector<ClangTidyError> &Errors, |