diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 3e40927d2..d781ddd92 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5247,30 +5247,27 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype) break; } - const Token *containerElementType = typeStart; - while (Token::Match(containerElementType, "%name%|::")) - containerElementType = containerElementType->next(); - // Try to determine type of "auto" token. // TODO: Get type better bool setType = false; ValueType autovt; const Type *templateArgType = nullptr; // container element type / smart pointer type - if (Token::Match(containerElementType, "< %type% *| *| >")) { - if (parsedecl(containerElementType->next(), &autovt, mDefaultSignedness, mSettings)) { + if (vt2->containerTypeToken) { + if (mSettings->library.isSmartPointer(vt2->containerTypeToken)) { + 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; + } + } else if (parsedecl(vt2->containerTypeToken, &autovt, mDefaultSignedness, mSettings)) { setType = true; - templateArgType = containerElementType->next()->type(); - } - } else if (mSettings->library.isSmartPointer(containerElementType->next())) { - const Token *smartPointerTypeTok = containerElementType->next(); - 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; + templateArgType = vt2->containerTypeToken->type(); } + } if (setType) { diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 0dc1a6fae..4d2db21a8 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6607,12 +6607,18 @@ private: // Container (vector) Settings set; Library::Container vector; - vector.startPattern = "Vector"; + vector.startPattern = "Vector <"; vector.startPattern2 = "Vector !!::"; vector.type_templateArgNo = 0; vector.arrayLike_indexOp = true; set.library.containers["Vector"] = vector; + Library::Container string; + string.startPattern = "test :: string"; + string.startPattern2 = "test :: string !!::"; + string.arrayLike_indexOp = string.stdStringLike = true; + set.library.containers["test::string"] = string; ASSERT_EQUALS("signed int", typeOf("Vector v; v[0]=3;", "[", "test.cpp", &set)); + ASSERT_EQUALS("container(test :: string)", typeOf("void foo(Vector v) { for (auto s: v) { x=s+s; } }", "s", "test.cpp", &set)); } // new