Commit b2397b6b authored by Nikolai Kosjar's avatar Nikolai Kosjar

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: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 817f12fd
......@@ -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;
};
......
......@@ -4,6 +4,10 @@ contains(CONFIG, dll) {
DEFINES += CPPTOOLS_STATIC_LIBRARY
}
HEADERS += $$PWD/senddocumenttracker.h
HEADERS += \
$$PWD/cppprojectfile.h \
$$PWD/senddocumenttracker.h \
SOURCES += $$PWD/senddocumenttracker.cpp
SOURCES += \
$$PWD/cppprojectfile.cpp \
$$PWD/senddocumenttracker.cpp
......@@ -64,6 +64,7 @@ DiagnosticContainer createDiagnostic(const QString &text,
);
}
const QString mainFileHeaderPath = QString::fromUtf8(TESTDATA_DIR "/someHeader.h");
const QString mainFilePath = QString::fromUtf8(TESTDATA_DIR "/diagnostic_erroneous_source.cpp");
const QString includedFilePath = QString::fromUtf8(TESTDATA_DIR "/diagnostic_erroneous_header.cpp");
......@@ -91,6 +92,22 @@ DiagnosticContainer warningFromMainFile()
mainFilePath);
}
DiagnosticContainer pragmaOnceWarningInHeader()
{
return createDiagnostic(
QStringLiteral("warning: #pragma once in main file"),
ClangBackEnd::DiagnosticSeverity::Warning,
mainFileHeaderPath);
}
DiagnosticContainer includeNextInPrimarySourceFileWarningInHeader()
{
return createDiagnostic(
QStringLiteral("warning: #include_next in primary source file"),
ClangBackEnd::DiagnosticSeverity::Warning,
mainFileHeaderPath);
}
DiagnosticContainer errorFromMainFile()
{
return createDiagnostic(
......@@ -193,6 +210,16 @@ TEST_F(ClangDiagnosticFilter, WarningsAreEmptyAfterTaking)
ASSERT_TRUE(clangDiagnosticFilter.takeWarnings().isEmpty());
}
TEST_F(ClangDiagnosticFilter, IgnoreCertainWarningsInHeaderFiles)
{
ClangCodeModel::Internal::ClangDiagnosticFilter myClangDiagnosticFilter{mainFileHeaderPath};
myClangDiagnosticFilter.filter({pragmaOnceWarningInHeader(),
includeNextInPrimarySourceFileWarningInHeader()});
ASSERT_TRUE(myClangDiagnosticFilter.takeWarnings().isEmpty());
}
TEST_F(ClangDiagnosticFilter, ErrorsAreEmptyAfterTaking)
{
clangDiagnosticFilter.filter({errorFromMainFile()});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment