clang-tidy: Suppress clang warnings

Those warnings should be printed via the clang code model, which can be
fine tuned to (de-)activate warnings. The clang-diagnostic-* warnings
from clang-tidy are not shown in the dialog an thus can not be
selectivly activated by the user.

Change-Id: I80b2cad227a9fd8fa0de253c73c40abfa8076be6
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Björn Schäpers
2020-12-10 07:32:46 +01:00
committed by Björn Schäpers
parent 3e2d224722
commit 8987996500
7 changed files with 3 additions and 55 deletions

View File

@@ -58,10 +58,10 @@ static QStringList tidyChecksArguments(const ClangDiagnosticConfig diagnosticCon
const ClangDiagnosticConfig::TidyMode tidyMode = diagnosticConfig.clangTidyMode();
// The argument "-config={}" stops stating/evaluating the .clang-tidy file.
if (tidyMode == ClangDiagnosticConfig::TidyMode::UseDefaultChecks)
return {"-config={}"};
return {"-config={}", "-checks=-clang-diagnostic-*"};
if (tidyMode == ClangDiagnosticConfig::TidyMode::UseCustomChecks)
return {"-config={}", "-checks=" + diagnosticConfig.clangTidyChecks()};
return {"--warnings-as-errors=-*"};
return {"-config={}", "-checks=" + diagnosticConfig.clangTidyChecks() + ",-clang-diagnostic-*"};
return {"--warnings-as-errors=-*", "-check=-clang-diagnostic-*"};
}
static QStringList clazyChecksArguments(const ClangDiagnosticConfig diagnosticConfig)

View File

@@ -960,9 +960,6 @@ void ClangTool::filter()
if (check.name.isEmpty()) {
check.name = checkName;
check.displayName = checkName;
const QString clangDiagPrefix = "clang-diagnostic-";
if (check.displayName.startsWith(clangDiagPrefix))
check.displayName = QString("-W%1").arg(check.name.mid(clangDiagPrefix.size()));
check.count = 1;
check.isShown = filterOptions ? filterOptions->checks.contains(checkName) : true;
check.hasFixit = check.hasFixit || item->diagnostic().hasFixits;

View File

@@ -1,5 +0,0 @@
// clang-tidy -export-fixes=clang.unused-parameter.yaml clang.unused-parameter.cpp -- -Wunused-parameter
#include "clang.unused-parameter.h"
void g(int g) {}

View File

@@ -1 +0,0 @@
void f(int i) {}

View File

@@ -1,10 +0,0 @@
---
MainSourceFile: 'FILE_PATH'
Diagnostics:
- DiagnosticName: clang-diagnostic-unused-parameter
DiagnosticMessage:
Message: 'unused parameter ''g'''
FilePath: 'FILE_PATH'
FileOffset: 153
Replacements: []
...

View File

@@ -1,10 +0,0 @@
---
MainSourceFile: 'FILE_PATH'
Diagnostics:
- DiagnosticName: clang-diagnostic-unused-parameter
DiagnosticMessage:
Message: 'unused parameter ''g'''
FilePath: 'FILE_PATH'
FileOffset: 156
Replacements: []
...

View File

@@ -146,29 +146,6 @@ TEST_F(ReadExportedDiagnostics, AcceptDiagsFromFilePaths_None)
ASSERT_THAT(diags, IsEmpty());
}
// Diagnostics from clang passed through via clang-tidy
TEST_F(ReadExportedDiagnostics, Tidy_Clang)
{
const QString sourceFile = TESTDATA "clang.unused-parameter.cpp";
const QString yamlSuffix
= QLatin1String(Utils::HostOsInfo::isWindowsHost() ? "_win.yaml" : ".yaml");
const QString exportedFile = createFile(appendYamlSuffix(TESTDATA "clang.unused-parameter"),
sourceFile);
Diagnostic expectedDiag;
expectedDiag.name = "clang-diagnostic-unused-parameter";
expectedDiag.location = {sourceFile, 4, 12};
expectedDiag.description = "unused parameter 'g' [clang-diagnostic-unused-parameter]";
expectedDiag.type = "warning";
expectedDiag.hasFixits = false;
Diagnostics diags = readExportedDiagnostics(Utils::FilePath::fromString(exportedFile),
{},
&errorMessage);
ASSERT_TRUE(errorMessage.isEmpty());
ASSERT_THAT(diags, ElementsAre(expectedDiag));
}
// Diagnostics from clang (static) analyzer passed through via clang-tidy
TEST_F(ReadExportedDiagnostics, Tidy_ClangAnalyzer)
{