Skip to content

Commit 40776f9

Browse files
authored
fixed #13828 - clang-tidy aliases in findings were not handled properly (#7502)
1 parent e478486 commit 40776f9

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

lib/cppcheck.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,26 +1974,28 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
19741974
const std::string errorString = line.substr(endErrorPos, line.length());
19751975

19761976
std::string fixedpath = Path::simplifyPath(line.substr(0, endNamePos));
1977+
fixedpath = Path::toNativeSeparators(std::move(fixedpath));
19771978
const auto lineNumber = strToInt<int64_t>(lineNumString);
19781979
const auto column = strToInt<int64_t>(columnNumString);
1979-
fixedpath = Path::toNativeSeparators(std::move(fixedpath));
19801980

19811981
ErrorMessage errmsg;
19821982
errmsg.callStack.emplace_back(fixedpath, lineNumber, column);
1983-
1984-
errmsg.id = "clang-tidy-" + errorString.substr(1, errorString.length() - 2);
1985-
if (errmsg.id.find("performance") != std::string::npos)
1986-
errmsg.severity = Severity::performance;
1987-
else if (errmsg.id.find("portability") != std::string::npos)
1988-
errmsg.severity = Severity::portability;
1989-
else if (errmsg.id.find("cert") != std::string::npos || errmsg.id.find("misc") != std::string::npos || errmsg.id.find("unused") != std::string::npos)
1990-
errmsg.severity = Severity::warning;
1991-
else
1992-
errmsg.severity = Severity::style;
1993-
19941983
errmsg.file0 = std::move(fixedpath);
19951984
errmsg.setmsg(trim(messageString));
1996-
mErrorLogger.reportErr(errmsg);
1985+
1986+
for (const auto& id : splitString(errorString.substr(1, errorString.length() - 2), ',')) {
1987+
errmsg.id = "clang-tidy-" + id;
1988+
if (errmsg.id.find("performance") != std::string::npos)
1989+
errmsg.severity = Severity::performance;
1990+
else if (errmsg.id.find("portability") != std::string::npos)
1991+
errmsg.severity = Severity::portability;
1992+
else if (errmsg.id.find("cert") != std::string::npos || errmsg.id.find("misc") != std::string::npos || errmsg.id.find("unused") != std::string::npos)
1993+
errmsg.severity = Severity::warning;
1994+
else
1995+
errmsg.severity = Severity::style;
1996+
1997+
mErrorLogger.reportErr(errmsg);
1998+
}
19971999
}
19982000
}
19992001

test/cli/other_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,6 +3463,44 @@ def test_clang_tidy_project(tmpdir):
34633463
__test_clang_tidy(tmpdir, True)
34643464

34653465

3466+
@pytest.mark.skipif(not has_clang_tidy, reason='clang-tidy is not available')
3467+
def test_clang_tidy_error_exit(tmp_path): # #13828
3468+
test_file = tmp_path / 'test.cpp'
3469+
with open(test_file, 'wt') as f:
3470+
f.write(
3471+
"""#include <string>
3472+
#include <utility>
3473+
3474+
// cppcheck-suppress clang-tidy-modernize-use-trailing-return-type
3475+
static bool f() // NOLINT(misc-use-anonymous-namespace)
3476+
{
3477+
std::string str;
3478+
const std::string str1 = std::move(str);
3479+
(void)str1;
3480+
return str.empty();
3481+
}""")
3482+
3483+
# TODO: remove project file usage when --clang-tidy works with non-project files
3484+
project_file = __write_compdb(tmp_path, str(test_file))
3485+
3486+
args = [
3487+
'-q',
3488+
'--template=simple',
3489+
'--inline-suppr',
3490+
'--std=c++11',
3491+
'--clang-tidy',
3492+
'--project={}'.format(project_file)
3493+
]
3494+
3495+
exitcode, stdout, stderr = cppcheck(args)
3496+
assert stdout.splitlines() == []
3497+
assert stderr.splitlines() == [
3498+
"{}:10:12: style: 'str' used after it was moved [clang-tidy-bugprone-use-after-move]".format(test_file),
3499+
"{}:10:12: style: 'str' used after it was moved [clang-tidy-hicpp-invalid-access-moved]".format(test_file)
3500+
]
3501+
assert exitcode == 0, stdout
3502+
3503+
34663504
def test_suppress_unmatched_wildcard(tmp_path): # #13660
34673505
test_file = tmp_path / 'test.c'
34683506
with open(test_file, 'wt') as f:

0 commit comments

Comments
 (0)