From a821533851920d0fdfe667452c2cd30b812e6421 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Wed, 11 Apr 2018 12:27:21 +0200 Subject: [PATCH] Clang: Suppress diagnostic "file 'x' from the precompiled header has been overridden" ...since it's not critical, only annoying to see. If this diagnostic occurs, changes in a non-project header will not be reflected in the main file. That's not a common case. Task-number: QTCREATORBUG-20125 Change-Id: Ic7b65506cdd6bc1c163050497d6f7c106a48d517 Reviewed-by: Ivan Donchevskii --- .../clangbackend/source/clangtranslationunit.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/tools/clangbackend/source/clangtranslationunit.cpp b/src/tools/clangbackend/source/clangtranslationunit.cpp index cce7548b3c2..ee22187dae2 100644 --- a/src/tools/clangbackend/source/clangtranslationunit.cpp +++ b/src/tools/clangbackend/source/clangtranslationunit.cpp @@ -234,6 +234,17 @@ static bool isHeaderErrorDiagnostic(const Utf8String &mainFilePath, const Diagno return isCritical && diagnostic.location().filePath() != mainFilePath; } +static bool isIgnoredHeaderErrorDiagnostic(const Diagnostic &diagnostic) +{ + // FIXME: This diagnostic can appear if e.g. a main file includes a -isystem header and then the + // header is opened in the editor - the provided unsaved file for the newly opened editor + // overrides the file from the preamble. In this case, clang uses the version from the preamble + // and changes in the header are not reflected in the main file. Typically that's not a problem + // because only non-project headers are opened as -isystem headers. + return diagnostic.text().endsWith( + Utf8StringLiteral("from the precompiled header has been overridden")); +} + void TranslationUnit::extractDiagnostics(DiagnosticContainer &firstHeaderErrorDiagnostic, QVector &mainFileDiagnostics) const { @@ -243,7 +254,9 @@ void TranslationUnit::extractDiagnostics(DiagnosticContainer &firstHeaderErrorDi bool hasFirstHeaderErrorDiagnostic = false; for (const Diagnostic &diagnostic : diagnostics()) { - if (!hasFirstHeaderErrorDiagnostic && isHeaderErrorDiagnostic(m_filePath, diagnostic)) { + if (!hasFirstHeaderErrorDiagnostic + && isHeaderErrorDiagnostic(m_filePath, diagnostic) + && !isIgnoredHeaderErrorDiagnostic(diagnostic)) { hasFirstHeaderErrorDiagnostic = true; firstHeaderErrorDiagnostic = diagnostic.toDiagnosticContainer(); }