diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 5a3a27fab..601a82f38 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5323,6 +5323,12 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype) return; } + if (vt1 && vt1->container && vt1->containerTypeToken && Token::Match(parent, ". %name% (") && vt1->container->getYield(parent->next()->str()) == Library::Container::Yield::ITEM) { + ValueType item; + if (parsedecl(vt1->containerTypeToken, &item, mDefaultSignedness, mSettings)) + setValueType(parent->tokAt(2), item); + } + if (vt1 && vt1->smartPointerType && Token::Match(parent, ". %name% (") && parent->originalName() == "->" && !parent->next()->function()) { const Scope *scope = vt1->smartPointerType->classScope; const Function *f = scope ? scope->findFunction(parent->next(), false) : nullptr; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 223a9d120..64ba9ff9c 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6868,6 +6868,7 @@ private: vector.startPattern2 = "Vector !!::"; vector.type_templateArgNo = 0; vector.arrayLike_indexOp = true; + vector.functions["front"] = Library::Container::Function{Library::Container::Action::NO_ACTION, Library::Container::Yield::ITEM}; set.library.containers["Vector"] = vector; Library::Container string; string.startPattern = "test :: string"; @@ -6878,6 +6879,7 @@ private: ASSERT_EQUALS("container(test :: string)", typeOf("{return test::string();}", "(", "test.cpp", &set)); ASSERT_EQUALS("container(test :: string)", typeOf("void foo(Vector v) { for (auto s: v) { x=s+s; } }", "s", "test.cpp", &set)); ASSERT_EQUALS("container(test :: string)", typeOf("void foo(Vector v) { for (auto s: v) { x=s+s; } }", "+", "test.cpp", &set)); + ASSERT_EQUALS("container(test :: string)", typeOf("Vector v; x = v.front();", "(", "test.cpp", &set)); } // new