diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e96234ed8..d7dc00c23 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1175,7 +1175,8 @@ void SymbolDatabase::createSymbolDatabaseSetVariablePointers() fixVarId(varIds, tok, const_cast(membertok), membervar); } } else if (const ::Type *type = var ? var->smartPointerType() : nullptr) { - const Variable *membervar = type->classScope->getVariable(membertok->str()); + const Scope *classScope = type->classScope; + const Variable *membervar = classScope ? classScope->getVariable(membertok->str()) : nullptr; if (membervar) { membertok->variable(membervar); if (membertok->varId() == 0 || mVariableList[membertok->varId()] == nullptr) diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 27a267ad8..5b9e266ed 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -352,6 +352,7 @@ private: TEST_CASE(findFunction27); TEST_CASE(findFunction28); TEST_CASE(findFunction29); + TEST_CASE(findFunction30); TEST_CASE(findFunctionContainer); TEST_CASE(findFunctionExternC); TEST_CASE(findFunctionGlobalScope); // ::foo @@ -5776,6 +5777,16 @@ private: ASSERT_EQUALS(2, foo->function()->token->linenr()); } + void findFunction30() { + GET_SYMBOL_DB("struct A;\n" + "void foo(std::shared_ptr ptr) {\n" + " int x = ptr->bar();\n" + "}"); + const Token *bar = Token::findsimplematch(tokenizer.tokens(), "bar ( ) ;"); + ASSERT(bar); + ASSERT(!bar->function()); + } + void findFunctionContainer() { { GET_SYMBOL_DB("void dostuff(std::vector v);\n"