#11733 FP unusedFunction with templates and --cppcheck-build-dir (#5085)

* #11733 FP unusedFunction with templates and --cppcheck-build-dir

* Add test
This commit is contained in:
chrchr-github 2023-05-26 06:13:48 +02:00 committed by GitHub
parent beea1a2345
commit bc03bed075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -454,7 +454,7 @@ void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLo
}
for (std::map<std::string, Location>::const_iterator decl = decls.cbegin(); decl != decls.cend(); ++decl) {
const std::string &functionName = decl->first;
const std::string &functionName = stripTemplateParameters(decl->first);
if (settings.library.isentrypoint(functionName))
continue;

View File

@ -0,0 +1,13 @@
namespace {
template <typename T>
T f() { return T(); }
}
// cppcheck-suppress unusedFunction
int g(int i) {
if (i == 0)
return f<char>();
if (i == 1)
return f<short>();
return f<int>();
}

View File

@ -83,6 +83,15 @@ def test_build_dir():
assert ret == 0, stdout
assert len(stderr) == 0
def test_build_dir_unused_template():
with tempfile.TemporaryDirectory() as tempdir:
args = f'--cppcheck-build-dir={tempdir} --enable=all --inline-suppr proj-inline-suppress/template.cpp'.split()
ret, stdout, stderr = cppcheck(args)
assert ret == 0, stdout
assert len(stderr) == 0
def test_suppress_unmatched_inline_suppression(): # 11172
ret, stdout, stderr = cppcheck(['--enable=all', '--suppress=unmatchedSuppression', '--inline-suppr', 'proj-inline-suppress/2.c'])
assert ret == 0, stdout