Fix #11182 checkLibraryFunction with overloaded method / #11198 inconsistent reporting of checkLibraryNoReturn (#4740)
This commit is contained in:
parent
fd15811215
commit
3ccc0adbca
|
@ -5414,7 +5414,13 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst) const
|
|||
else
|
||||
unknownDeref = true;
|
||||
}
|
||||
const ValueType::MatchResult res = ValueType::matchParameter(arguments[j]->valueType(), var, funcarg);
|
||||
const Token* valuetok = arguments[j];
|
||||
if (valuetok->str() == "::") {
|
||||
const Token* rml = nextAfterAstRightmostLeaf(vartok);
|
||||
if (rml)
|
||||
valuetok = rml->previous();
|
||||
}
|
||||
const ValueType::MatchResult res = ValueType::matchParameter(valuetok->valueType(), var, funcarg);
|
||||
if (res == ValueType::MatchResult::SAME)
|
||||
++same;
|
||||
else if (res == ValueType::MatchResult::FALLBACK1)
|
||||
|
@ -7464,7 +7470,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
|
|||
if (call->constness == 0 && func->constness != 0 && func->reference != Reference::None)
|
||||
return ValueType::MatchResult::NOMATCH;
|
||||
}
|
||||
if (call->type != func->type) {
|
||||
if (call->type != func->type || (call->isEnum() && !func->isEnum())) {
|
||||
if (call->type == ValueType::Type::VOID || func->type == ValueType::Type::VOID)
|
||||
return ValueType::MatchResult::FALLBACK1;
|
||||
if (call->pointer > 0)
|
||||
|
|
|
@ -7176,7 +7176,7 @@ bool Tokenizer::isScopeNoReturn(const Token *endScopeToken, bool *unknown) const
|
|||
bool warn = true;
|
||||
if (Token::simpleMatch(endScopeToken->tokAt(-2), ") ; }")) {
|
||||
const Token * const ftok = endScopeToken->linkAt(-2)->previous();
|
||||
if (ftok && ftok->type()) // constructor call
|
||||
if (ftok && (ftok->type() || (ftok->function() && ftok->function()->hasBody()))) // constructor call
|
||||
warn = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -4337,7 +4337,6 @@ void valid_vsprintf_helper(const char * format, ...)
|
|||
void valid_vsprintf()
|
||||
{
|
||||
// buffer will contain "2\0" => no bufferAccessOutOfBounds
|
||||
// cppcheck-suppress checkLibraryNoReturn
|
||||
valid_vsprintf_helper("%1.0f", 2.0f);
|
||||
}
|
||||
|
||||
|
|
|
@ -212,6 +212,7 @@ private:
|
|||
TEST_CASE(configuration3);
|
||||
TEST_CASE(configuration4);
|
||||
TEST_CASE(configuration5);
|
||||
TEST_CASE(configuration6);
|
||||
|
||||
TEST_CASE(ptrptr);
|
||||
|
||||
|
@ -2503,6 +2504,14 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:5]: (error) Resource leak: file\n", errout.str());
|
||||
}
|
||||
|
||||
void configuration6() { // #11198
|
||||
check("void f() {}\n"
|
||||
"void g() {\n"
|
||||
" f();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void ptrptr() {
|
||||
check("void f() {\n"
|
||||
" char **p = malloc(10);\n"
|
||||
|
|
|
@ -62,7 +62,7 @@ private:
|
|||
ASSERT_EQUALS(8, platform.sizeof_long_long);
|
||||
}
|
||||
|
||||
void valid_config_native_1() {
|
||||
void valid_config_native_1() const {
|
||||
// Verify if native Win32A platform is loaded correctly
|
||||
cppcheck::Platform platform;
|
||||
ASSERT(platform.platform(cppcheck::Platform::Win32A));
|
||||
|
@ -81,7 +81,7 @@ private:
|
|||
ASSERT_EQUALS(64, platform.long_long_bit);
|
||||
}
|
||||
|
||||
void valid_config_native_2() {
|
||||
void valid_config_native_2() const {
|
||||
// Verify if native Unix64 platform is loaded correctly
|
||||
cppcheck::Platform platform;
|
||||
ASSERT(platform.platform(cppcheck::Platform::Unix64));
|
||||
|
|
|
@ -437,6 +437,7 @@ private:
|
|||
TEST_CASE(findFunction41); // #10202
|
||||
TEST_CASE(findFunction42);
|
||||
TEST_CASE(findFunction43); // #10087
|
||||
TEST_CASE(findFunction44); // #11182
|
||||
TEST_CASE(findFunctionContainer);
|
||||
TEST_CASE(findFunctionExternC);
|
||||
TEST_CASE(findFunctionGlobalScope); // ::foo
|
||||
|
@ -6926,6 +6927,37 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void findFunction44() { // #11182
|
||||
{
|
||||
GET_SYMBOL_DB("struct T { enum E { E0 }; };\n"
|
||||
"struct S {\n"
|
||||
" void f(const void*, T::E) {}\n"
|
||||
" void f(const int&, T::E) {}\n"
|
||||
" void g() { f(nullptr, T::E0); }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "f ( nullptr");
|
||||
ASSERT(functok);
|
||||
ASSERT(functok->function());
|
||||
ASSERT(functok->function()->name() == "f");
|
||||
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
|
||||
}
|
||||
{
|
||||
GET_SYMBOL_DB("enum E { E0 };\n"
|
||||
"struct S {\n"
|
||||
" void f(int*, int) {}\n"
|
||||
" void f(int, int) {}\n"
|
||||
" void g() { f(nullptr, E0); }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "f ( nullptr");
|
||||
ASSERT(functok);
|
||||
ASSERT(functok->function());
|
||||
ASSERT(functok->function()->name() == "f");
|
||||
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void findFunctionContainer() {
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue