aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/ClangTidyDiagnosticConsumer.cpp
diff options
context:
space:
mode:
authorJonathan Roelofs <jonathan@codesourcery.com>2016-01-13 17:36:41 +0000
committerJonathan Roelofs <jonathan@codesourcery.com>2016-01-13 17:36:41 +0000
commitf502328e6cf163245287d54694b089637ffdddfe (patch)
tree202a61141bb80ec801c5d7ecc0ec4bd81d87219d /clang-tidy/ClangTidyDiagnosticConsumer.cpp
parente2ddab9dc5484edc870fe8ff19c9762ef6373dba (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/ClangTidyDiagnosticConsumer.cpp')
-rw-r--r--clang-tidy/ClangTidyDiagnosticConsumer.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index ac216753..320a50a9 100644
--- a/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -115,8 +115,10 @@ ClangTidyMessage::ClangTidyMessage(StringRef Message,
}
ClangTidyError::ClangTidyError(StringRef CheckName,
- ClangTidyError::Level DiagLevel)
- : CheckName(CheckName), DiagLevel(DiagLevel) {}
+ ClangTidyError::Level DiagLevel,
+ bool IsWarningAsError)
+ : CheckName(CheckName), DiagLevel(DiagLevel),
+ IsWarningAsError(IsWarningAsError) {}
// Returns true if GlobList starts with the negative indicator ('-'), removes it
// from the GlobList.
@@ -204,6 +206,7 @@ void ClangTidyContext::setCurrentFile(StringRef File) {
CurrentFile = File;
CurrentOptions = getOptionsForFile(CurrentFile);
CheckFilter.reset(new GlobList(*getOptions().Checks));
+ WarningAsErrorFilter.reset(new GlobList(*getOptions().WarningsAsErrors));
}
void ClangTidyContext::setASTContext(ASTContext *Context) {
@@ -237,6 +240,11 @@ bool ClangTidyContext::isCheckEnabled(StringRef CheckName) const {
return CheckFilter->contains(CheckName);
}
+GlobList &ClangTidyContext::getWarningAsErrorFilter() {
+ assert(WarningAsErrorFilter != nullptr);
+ return *WarningAsErrorFilter;
+}
+
/// \brief Store a \c ClangTidyError.
void ClangTidyContext::storeError(const ClangTidyError &Error) {
Errors.push_back(Error);
@@ -324,7 +332,10 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
LastErrorRelatesToUserCode = true;
LastErrorPassesLineFilter = true;
}
- Errors.push_back(ClangTidyError(CheckName, Level));
+ bool IsWarningAsError =
+ DiagLevel == DiagnosticsEngine::Warning &&
+ Context.getWarningAsErrorFilter().contains(CheckName);
+ Errors.push_back(ClangTidyError(CheckName, Level, IsWarningAsError));
}
// FIXME: Provide correct LangOptions for each file.