From df360704f00a4274cc7c616b91302bf1fae8b8e8 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 6 Nov 2023 17:30:38 +0100 Subject: [PATCH] ClangTools: Suppress bogus clazy warning about #pragma once We don't pass the correct value "c++header" to the -x option, because to clang that implies building a precompiled header, which apparently switches on some different mode that breaks clang-tidy and clazy. On the other hand, with "-x c++" clazy now thinks that this is a source file and frowns at "#pragma once". Suppress this warning for header files. Amends 60fca0596adfc98af9e3ef4e657d90eec4af9486. We might run into similar "header vs source" problems in the future. I don't see anything better than suppressing them one by one. Fixes: QTCREATORBUG-29781 Change-Id: Ia15ac5b278777e2b2e089e9d58bb7537c38955ce Reviewed-by: David Schulz --- src/plugins/clangtools/clangtoolrunner.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/clangtools/clangtoolrunner.cpp b/src/plugins/clangtools/clangtoolrunner.cpp index e83037aa536..23c249d3489 100644 --- a/src/plugins/clangtools/clangtoolrunner.cpp +++ b/src/plugins/clangtools/clangtoolrunner.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -76,14 +77,17 @@ static QStringList checksArguments(const AnalyzeInputData &input) return {}; } -static QStringList clangArguments(const ClangDiagnosticConfig &diagnosticConfig, - const QStringList &baseOptions) +static QStringList clangArguments(const AnalyzeInputData &input) { QStringList arguments; + const ClangDiagnosticConfig &diagnosticConfig = input.config; + const QStringList &baseOptions = input.unit.arguments; arguments << ClangDiagnosticConfigsModel::globalDiagnosticOptions() << (isClMode(baseOptions) ? clangArgsForCl(diagnosticConfig.clangOptions()) : diagnosticConfig.clangOptions()) << baseOptions; + if (ProjectFile::isHeader(input.unit.file)) + arguments << "-Wno-pragma-once-outside-header"; if (LOG().isDebugEnabled()) arguments << QLatin1String("-v"); @@ -157,7 +161,7 @@ GroupItem clangToolTask(const AnalyzeInputData &input, const QStringList args = checksArguments(input) + mainToolArguments(data) + QStringList{"--"} - + clangArguments(input.config, input.unit.arguments); + + clangArguments(input); const CommandLine commandLine = {data.executable, args}; qCDebug(LOG).noquote() << "Starting" << commandLine.toUserOutput();