Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ void SymbolDatabase::createSymbolDatabaseSetVariablePointers()
Token* memberTok = tok->next()->link()->tokAt(2);
const Scope* scope = vt->containerTypeToken->scope();
const Type* contType{};
const std::string typeStr = vt->containerTypeToken->expressionString();
const std::string& typeStr = vt->containerTypeToken->str(); // TODO: handle complex type expressions
while (scope && !contType) {
contType = scope->findType(typeStr); // find the type stored in the container
scope = scope->nestedIn;
Expand Down Expand Up @@ -2276,20 +2276,27 @@ void Variable::setValueType(const ValueType &valueType)
setFlag(fIsSmartPointer, true);
}

const Type *Variable::smartPointerType() const
const Type* Variable::smartPointerType() const
{
if (!isSmartPointer())
return nullptr;

if (mValueType->smartPointerType)
return mValueType->smartPointerType;

// TODO: Cache result
const Token *ptrType = typeStartToken();
while (Token::Match(ptrType, "%name%|::"))
ptrType = ptrType->next();
if (Token::Match(ptrType, "< %name% >"))
return ptrType->scope()->findType(ptrType->next()->str());
// TODO: Cache result, handle more complex type expression
const Token* typeTok = typeStartToken();
while (Token::Match(typeTok, "%name%|::"))
typeTok = typeTok->next();
if (Token::Match(typeTok, "< %name% >")) {
const Scope* scope = typeTok->scope();
const Type* ptrType{};
while (scope && !ptrType) {
Comment thread
danmar marked this conversation as resolved.
ptrType = scope->findType(typeTok->next()->str());
scope = scope->nestedIn;
}
return ptrType;
}
return nullptr;
}

Expand Down
11 changes: 11 additions & 0 deletions test/testfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,17 @@ class TestFunctions : public TestFixture {
"}\n");
ASSERT_EQUALS("", errout.str());

check("struct S {\n" // #11543
" 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 std::shared_ptr<S>& c : v)\n"
" c->f(i);\n"
"}\n");
ASSERT_EQUALS("", errout.str());

check("namespace N {\n"
" struct S { static const std::set<std::string> s; };\n"
"}\n"
Expand Down