Fix #11223 checkLibraryFunction treats "auto" as type (#4605)

* Fix #11223 checkLibraryFunction treats "auto" as type

* Use utility function
This commit is contained in:
chrchr-github 2022-12-02 07:21:33 +01:00 committed by GitHub
parent 883908b439
commit 9efedd6be9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -2264,6 +2264,11 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token * tok)
if (r.first)
return r;
}
if (astIsRangeBasedForDecl(var->nameToken()) && astIsContainer(var->nameToken()->astParent()->astOperand2())) { // range-based for
const ValueType* vt = var->nameToken()->astParent()->astOperand2()->valueType();
if (vt && vt->containerTypeToken)
return { vt->containerTypeToken, vt->containerTypeToken->linkAt(-1) };
}
}
return {var->typeStartToken(), var->typeEndToken()->next()};
} else if (Token::simpleMatch(tok, "return")) {

View File

@ -1900,6 +1900,12 @@ private:
"void g() { C::f(); }\n");
ASSERT_EQUALS("", errout.str());
check("void f(const std::vector<std::string>& v) {\n" // #11223
" for (const auto& s : v)\n"
" s.find(\"\");\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function s.find() is not used.\n", errout.str());
settings.severity = severity_old;
settings.checkLibrary = false;
}