Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from danmar:main #131

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, const Suppre
if (settings.inlineSuppressions) {
// report unmatched unusedFunction suppressions
err |= SuppressionList::reportUnmatchedSuppressions(
suppressions.getUnmatchedInlineSuppressions(), errorLogger);
suppressions.getUnmatchedInlineSuppressions(unusedFunctionCheckEnabled), errorLogger);
}

err |= SuppressionList::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(unusedFunctionCheckEnabled), errorLogger);
Expand Down
4 changes: 3 additions & 1 deletion lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedGlobalSuppr
return result;
}

std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedInlineSuppressions() const
std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedInlineSuppressions(const bool includeUnusedFunction) const
{
std::list<SuppressionList::Suppression> result;
for (const SuppressionList::Suppression &s : SuppressionList::mSuppressions) {
Expand All @@ -576,6 +576,8 @@ std::list<SuppressionList::Suppression> SuppressionList::getUnmatchedInlineSuppr
continue;
if (s.hash > 0)
continue;
if (!includeUnusedFunction && s.errorId == ID_UNUSEDFUNCTION)
continue;
result.push_back(s);
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion lib/suppressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class CPPCHECKLIB SuppressionList {
* @brief Returns list of unmatched inline suppressions.
* @return list of unmatched suppressions
*/
std::list<Suppression> getUnmatchedInlineSuppressions() const;
std::list<Suppression> getUnmatchedInlineSuppressions(bool includeUnusedFunction) const;

/**
* @brief Returns list of all suppressions.
Expand Down
20 changes: 19 additions & 1 deletion test/cli/inline-suppress_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,22 @@ def test_unused_function_unmatched_builddir_j_thread(tmpdir):
def test_unused_function_unmatched_builddir_j_process(tmpdir):
build_dir = os.path.join(tmpdir, 'b1')
os.mkdir(build_dir)
__test_unused_function_unmatched(tmpdir, ['-j2', '--cppcheck-build-dir={}'.format(build_dir), '--executor=process'])
__test_unused_function_unmatched(tmpdir, ['-j2', '--cppcheck-build-dir={}'.format(build_dir), '--executor=process'])


# do not report unmatched unusedFunction inline suppressions when unusedFunction check is disabled
def test_unused_function_disabled_unmatched():
args = [
'-q',
'--template=simple',
'--enable=warning,information',
'--inline-suppr',
'proj-inline-suppress/unusedFunctionUnmatched.cpp'
]

ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
assert stderr.splitlines() == [
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path)
]
assert stdout == ''
assert ret == 0, stdout
Loading