diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ecd35539b..6f91a86f6 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5698,6 +5698,7 @@ void SymbolDatabase::setValueType(Token *tok, const Variable &var) valuetype.typeScope = var.typeScope(); if (var.valueType()) { valuetype.container = var.valueType()->container; + valuetype.containerTypeToken = var.valueType()->containerTypeToken; } valuetype.smartPointerType = var.smartPointerType(); if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings)) { @@ -6548,20 +6549,13 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to const Token *typeStartToken = tok->astOperand1(); while (typeStartToken && typeStartToken->str() == "::") typeStartToken = typeStartToken->astOperand1(); - if (const Library::Container *c = mSettings->library.detectContainer(typeStartToken)) { + if (mSettings->library.detectContainer(typeStartToken) || + mSettings->library.detectSmartPointer(typeStartToken)) { ValueType vt; - vt.pointer = 0; - vt.container = c; - vt.type = ValueType::Type::CONTAINER; - setValueType(tok, vt); - continue; - } - if (const Library::SmartPointer* sp = mSettings->library.detectSmartPointer(typeStartToken)) { - ValueType vt; - vt.type = ValueType::Type::SMART_POINTER; - vt.smartPointer = sp; - setValueType(tok, vt); - continue; + if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings)) { + setValueType(tok, vt); + continue; + } } const std::string e = tok->astOperand1()->expressionString(); diff --git a/test/teststl.cpp b/test/teststl.cpp index 719ea3bbc..8bd2845e9 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -4925,6 +4925,18 @@ private: " cb[i] = b[i];\n" "}\n",true); ASSERT_EQUALS("", errout.str()); + + // #9836 + check("void f() {\n" + " auto v = std::vector >{ std::vector{ \"hello\" } };\n" + " auto p = &(v.at(0).at(0));\n" + " v.clear();\n" + " std::cout << *p << std::endl;\n" + "}\n", + true); + ASSERT_EQUALS( + "[test.cpp:3] -> [test.cpp:3] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:5]: (error) Using pointer to local variable 'v' that may be invalid.\n", + errout.str()); } void invalidContainerLoop() {