diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 2716c27a6..7c9f2d865 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1240,7 +1240,7 @@ void SymbolDatabase::createSymbolDatabaseSetVariablePointers() membertok = membertok->astOperand2(); } - if (membertok) { + if (membertok && membertok != tok) { const Variable *var = tok->variable(); if (var->typeScope()) { const Variable *membervar = var->typeScope()->getVariable(membertok->str()); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index a260bddef..4c95fac28 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -185,6 +185,7 @@ private: TEST_CASE(arrayMemberVar1); TEST_CASE(arrayMemberVar2); TEST_CASE(arrayMemberVar3); + TEST_CASE(arrayMemberVar4); TEST_CASE(staticMemberVar); TEST_CASE(getVariableFromVarIdBoundsCheck); @@ -1433,6 +1434,19 @@ private: ASSERT(tok && tok->varId() == 3U); // It's possible to set a varId } + void arrayMemberVar4() { + GET_SYMBOL_DB("struct S { unsigned char* s; };\n" + "struct T { S s[38]; };\n" + "void f(T* t) {\n" + " t->s;\n" + "}\n"); + const Token *tok = Token::findsimplematch(tokenizer.tokens(), ". s"); + tok = tok ? tok->next() : nullptr; + ASSERT(db != nullptr); + ASSERT(tok && tok->variable() && Token::simpleMatch(tok->variable()->typeStartToken(), "S s [ 38 ] ;")); + ASSERT(tok && tok->varId() == 4U); + } + void staticMemberVar() { GET_SYMBOL_DB("class Foo {\n" " static const double d;\n"