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 60fca0596a.
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 <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2023-11-06 17:30:38 +01:00
parent 210907529f
commit df360704f0

View File

@@ -10,6 +10,7 @@
#include <coreplugin/icore.h>
#include <cppeditor/clangdiagnosticconfigsmodel.h>
#include <cppeditor/cppprojectfile.h>
#include <cppeditor/cpptoolsreuse.h>
#include <extensionsystem/pluginmanager.h>
@@ -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();