Skip to content

Commit 8fb8e06

Browse files
committed
SymbolDatabase: Set valuetype for this
1 parent 15d3e51 commit 8fb8e06

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/symboldatabase.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7033,6 +7033,18 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
70337033
parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mSettings, mIsCpp);
70347034
setValueType(tok, vt);
70357035
}
7036+
} else if (tok->isKeyword() && tok->str() == "this" && tok->scope()->isExecutable()) {
7037+
const Scope* fscope = tok->scope();
7038+
while (fscope && !fscope->function)
7039+
fscope = fscope->nestedIn;
7040+
const Scope* defScope = fscope && fscope->function->tokenDef ? fscope->function->tokenDef->scope() : nullptr;
7041+
if (defScope && defScope->isClassOrStruct()) {
7042+
ValueType vt(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::RECORD, 1);
7043+
vt.typeScope = defScope;
7044+
if (fscope->function->isConst())
7045+
vt.constness = 1;
7046+
setValueType(tok, vt);
7047+
}
70367048
}
70377049
}
70387050

test/testsymboldatabase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ class TestSymbolDatabase : public TestFixture {
473473

474474
TEST_CASE(valueType1);
475475
TEST_CASE(valueType2);
476+
TEST_CASE(valueTypeThis);
476477

477478
TEST_CASE(variadic1); // #7453
478479
TEST_CASE(variadic2); // #7649
@@ -7923,6 +7924,11 @@ class TestSymbolDatabase : public TestFixture {
79237924
}
79247925
}
79257926

7927+
void valueTypeThis() {
7928+
ASSERT_EQUALS("C *", typeOf("class C { C() { *this = 0; } };", "this"));
7929+
ASSERT_EQUALS("const C *", typeOf("class C { void foo() const; }; void C::foo() const { *this = 0; }", "this"));
7930+
}
7931+
79267932
void variadic1() { // #7453
79277933
{
79287934
GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"

0 commit comments

Comments
 (0)