Partial fix for #11604: no DacaWrongData for function pointer (#4867)

This commit is contained in:
chrchr-github 2023-03-12 15:49:37 +01:00 committed by GitHub
parent e2b2fc2684
commit a75392307f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View File

@ -250,7 +250,7 @@ void CheckFunctions::checkIgnoredReturnValue()
else if (Token::Match(tok, "[(<]") && tok->link())
tok = tok->link();
if (tok->varId() || !Token::Match(tok, "%name% (") || tok->isKeyword())
if (tok->varId() || tok->isKeyword() || tok->isStandardType() || !Token::Match(tok, "%name% ("))
continue;
const Token *parent = tok->next()->astParent();

View File

@ -1310,7 +1310,7 @@ void CheckStl::negativeIndex()
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Scope * scope : symbolDatabase->functionScopes) {
for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
if (!Token::Match(tok, "%var% [") || WRONG_DATA(!tok->next()->astOperand2(), tok))
if (!Token::Match(tok, "%var% [") || !tok->next()->astOperand2())
continue;
const Variable * const var = tok->variable();
if (!var || tok == var->nameToken())

View File

@ -1826,6 +1826,7 @@ private:
void checkLibraryMatchFunctions() {
const auto settings_old = settings;
settings.checkLibrary = true;
settings.daca = true;
check("void f() {\n"
" lib_func();"
@ -1992,6 +1993,11 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f() {\n" // #11604
" int (*g)() = nullptr;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
settings = settings_old;
}

View File

@ -2319,6 +2319,16 @@ private:
" return sum;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
const auto oldSettings = settings;
settings.daca = true;
check("void f() {\n"
" const char a[][5] = { \"1\", \"true\", \"on\", \"yes\" };\n"
"}\n");
ASSERT_EQUALS("", errout.str());
settings = oldSettings;
}