Fix regression: wrong member variable (#3987)

This commit is contained in:
chrchr-github 2022-04-08 08:23:10 +02:00 committed by GitHub
parent d2a0b0f78e
commit 38bc0ad4c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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());

View File

@ -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"