Skip to content

Commit 3ccc0ad

Browse files
Fix #11182 checkLibraryFunction with overloaded method / #11198 inconsistent reporting of checkLibraryNoReturn (danmar#4740)
1 parent fd15811 commit 3ccc0ad

File tree

6 files changed

+52
-6
lines changed

6 files changed

+52
-6
lines changed

lib/symboldatabase.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -5414,7 +5414,13 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
54145414
else
54155415
unknownDeref = true;
54165416
}
5417-
const ValueType::MatchResult res = ValueType::matchParameter(arguments[j]->valueType(), var, funcarg);
5417+
const Token* valuetok = arguments[j];
5418+
if (valuetok->str() == "::") {
5419+
const Token* rml = nextAfterAstRightmostLeaf(vartok);
5420+
if (rml)
5421+
valuetok = rml->previous();
5422+
}
5423+
const ValueType::MatchResult res = ValueType::matchParameter(valuetok->valueType(), var, funcarg);
54185424
if (res == ValueType::MatchResult::SAME)
54195425
++same;
54205426
else if (res == ValueType::MatchResult::FALLBACK1)
@@ -7464,7 +7470,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
74647470
if (call->constness == 0 && func->constness != 0 && func->reference != Reference::None)
74657471
return ValueType::MatchResult::NOMATCH;
74667472
}
7467-
if (call->type != func->type) {
7473+
if (call->type != func->type || (call->isEnum() && !func->isEnum())) {
74687474
if (call->type == ValueType::Type::VOID || func->type == ValueType::Type::VOID)
74697475
return ValueType::MatchResult::FALLBACK1;
74707476
if (call->pointer > 0)

lib/tokenize.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7176,7 +7176,7 @@ bool Tokenizer::isScopeNoReturn(const Token *endScopeToken, bool *unknown) const
71767176
bool warn = true;
71777177
if (Token::simpleMatch(endScopeToken->tokAt(-2), ") ; }")) {
71787178
const Token * const ftok = endScopeToken->linkAt(-2)->previous();
7179-
if (ftok && ftok->type()) // constructor call
7179+
if (ftok && (ftok->type() || (ftok->function() && ftok->function()->hasBody()))) // constructor call
71807180
warn = false;
71817181
}
71827182

test/cfg/std.c

-1
Original file line numberDiff line numberDiff line change
@@ -4337,7 +4337,6 @@ void valid_vsprintf_helper(const char * format, ...)
43374337
void valid_vsprintf()
43384338
{
43394339
// buffer will contain "2\0" => no bufferAccessOutOfBounds
4340-
// cppcheck-suppress checkLibraryNoReturn
43414340
valid_vsprintf_helper("%1.0f", 2.0f);
43424341
}
43434342

test/testleakautovar.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class TestLeakAutoVar : public TestFixture {
212212
TEST_CASE(configuration3);
213213
TEST_CASE(configuration4);
214214
TEST_CASE(configuration5);
215+
TEST_CASE(configuration6);
215216

216217
TEST_CASE(ptrptr);
217218

@@ -2503,6 +2504,14 @@ class TestLeakAutoVar : public TestFixture {
25032504
ASSERT_EQUALS("[test.cpp:5]: (error) Resource leak: file\n", errout.str());
25042505
}
25052506

2507+
void configuration6() { // #11198
2508+
check("void f() {}\n"
2509+
"void g() {\n"
2510+
" f();\n"
2511+
"}\n");
2512+
ASSERT_EQUALS("", errout.str());
2513+
}
2514+
25062515
void ptrptr() {
25072516
check("void f() {\n"
25082517
" char **p = malloc(10);\n"

test/testplatform.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TestPlatform : public TestFixture {
6262
ASSERT_EQUALS(8, platform.sizeof_long_long);
6363
}
6464

65-
void valid_config_native_1() {
65+
void valid_config_native_1() const {
6666
// Verify if native Win32A platform is loaded correctly
6767
cppcheck::Platform platform;
6868
ASSERT(platform.platform(cppcheck::Platform::Win32A));
@@ -81,7 +81,7 @@ class TestPlatform : public TestFixture {
8181
ASSERT_EQUALS(64, platform.long_long_bit);
8282
}
8383

84-
void valid_config_native_2() {
84+
void valid_config_native_2() const {
8585
// Verify if native Unix64 platform is loaded correctly
8686
cppcheck::Platform platform;
8787
ASSERT(platform.platform(cppcheck::Platform::Unix64));

test/testsymboldatabase.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ class TestSymbolDatabase : public TestFixture {
437437
TEST_CASE(findFunction41); // #10202
438438
TEST_CASE(findFunction42);
439439
TEST_CASE(findFunction43); // #10087
440+
TEST_CASE(findFunction44); // #11182
440441
TEST_CASE(findFunctionContainer);
441442
TEST_CASE(findFunctionExternC);
442443
TEST_CASE(findFunctionGlobalScope); // ::foo
@@ -6926,6 +6927,37 @@ class TestSymbolDatabase : public TestFixture {
69266927
}
69276928
}
69286929

6930+
void findFunction44() { // #11182
6931+
{
6932+
GET_SYMBOL_DB("struct T { enum E { E0 }; };\n"
6933+
"struct S {\n"
6934+
" void f(const void*, T::E) {}\n"
6935+
" void f(const int&, T::E) {}\n"
6936+
" void g() { f(nullptr, T::E0); }\n"
6937+
"};\n");
6938+
ASSERT_EQUALS("", errout.str());
6939+
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "f ( nullptr");
6940+
ASSERT(functok);
6941+
ASSERT(functok->function());
6942+
ASSERT(functok->function()->name() == "f");
6943+
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
6944+
}
6945+
{
6946+
GET_SYMBOL_DB("enum E { E0 };\n"
6947+
"struct S {\n"
6948+
" void f(int*, int) {}\n"
6949+
" void f(int, int) {}\n"
6950+
" void g() { f(nullptr, E0); }\n"
6951+
"};\n");
6952+
ASSERT_EQUALS("", errout.str());
6953+
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "f ( nullptr");
6954+
ASSERT(functok);
6955+
ASSERT(functok->function());
6956+
ASSERT(functok->function()->name() == "f");
6957+
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
6958+
}
6959+
}
6960+
69296961

69306962
void findFunctionContainer() {
69316963
{

0 commit comments

Comments
 (0)