Partial fix for #11543 checkLibraryFunction warning for smartpointer in container (#4900)

This commit is contained in:
chrchr-github 2023-03-27 17:50:33 +02:00 committed by GitHub
parent c79d859f8b
commit 5791561a45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View File

@ -6379,11 +6379,12 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source
const Token *smartPointerTypeTok = vt2->containerTypeToken;
while (Token::Match(smartPointerTypeTok, "%name%|::"))
smartPointerTypeTok = smartPointerTypeTok->next();
if (Token::Match(smartPointerTypeTok, "< %name% > >") && smartPointerTypeTok->next()->type()) {
setType = true;
templateArgType = smartPointerTypeTok->next()->type();
autovt.smartPointerType = templateArgType;
autovt.type = ValueType::Type::NONSTD;
if (Token::simpleMatch(smartPointerTypeTok, "<")) {
if ((templateArgType = findTypeInNested(smartPointerTypeTok->next(), tok->scope()))) {
setType = true;
autovt.smartPointerType = templateArgType;
autovt.type = ValueType::Type::NONSTD;
}
}
} else if (parsedecl(vt2->containerTypeToken, &autovt, mDefaultSignedness, mSettings, mIsCpp)) {
setType = true;

View File

@ -8223,6 +8223,24 @@ private:
ASSERT(tok && tok->valueType());
ASSERT_EQUALS("iterator(std :: vector <)", tok->valueType()->str());
}
{
GET_SYMBOL_DB("struct S {\n"
" S() {}\n"
" std::vector<std::shared_ptr<S>> v;\n"
" void f(int i) const;\n"
"};\n"
"void S::f(int i) const {\n"
" for (const auto& c : v)\n"
" c->f(i);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
const Token* tok = tokenizer.tokens();
tok = Token::findsimplematch(tok, "auto");
ASSERT(tok && tok->valueType() && tok->scope() && tok->scope()->functionOf);
const Type* smpType = tok->valueType()->smartPointerType;
ASSERT(smpType && smpType == tok->scope()->functionOf->definedType);
}
}
void valueTypeThis() {