Clang: Ignore certain warnings in header files

We already had this workarounded, but it got lost in the refactorings.

Task-number: QTCREATORBUG-12067
Change-Id: Ie01f9d41f25d17d1b595204748634bc87ef44378
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2016-01-25 16:38:28 +01:00
parent 817f12fddd
commit b2397b6b4f
3 changed files with 54 additions and 3 deletions

View File

@@ -25,6 +25,10 @@
#include "clangdiagnosticfilter.h"
#include <cpptools/cppprojectfile.h>
#include <utf8stringvector.h>
namespace {
bool isWarningOrNote(ClangBackEnd::DiagnosticSeverity severity)
@@ -41,6 +45,17 @@ bool isWarningOrNote(ClangBackEnd::DiagnosticSeverity severity)
Q_UNREACHABLE();
}
bool isBlackListedDiagnostic(const ClangBackEnd::DiagnosticContainer &diagnostic,
bool isHeaderFile)
{
static const Utf8StringVector blackList {
Utf8StringLiteral("warning: #pragma once in main file"),
Utf8StringLiteral("warning: #include_next in primary source file")
};
return isHeaderFile && blackList.contains(diagnostic.text());
}
template <class Condition>
QVector<ClangBackEnd::DiagnosticContainer>
filterDiagnostics(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics,
@@ -76,8 +91,13 @@ namespace Internal {
void ClangDiagnosticFilter::filterDocumentRelatedWarnings(
const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics)
{
const auto isLocalWarning = [this] (const ClangBackEnd::DiagnosticContainer &diagnostic) {
using namespace CppTools;
const bool isHeaderFile = ProjectFile::isHeader(ProjectFile::classify(m_filePath));
const auto isLocalWarning = [this, isHeaderFile]
(const ClangBackEnd::DiagnosticContainer &diagnostic) {
return isWarningOrNote(diagnostic.severity())
&& !isBlackListedDiagnostic(diagnostic, isHeaderFile)
&& diagnostic.location().filePath() == m_filePath;
};