diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 746811d66..7f205c8e6 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -7033,6 +7033,18 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to parsedecl(fscope->function->retDef, &vt, mDefaultSignedness, mSettings, mIsCpp); setValueType(tok, vt); } + } else if (tok->isKeyword() && tok->str() == "this" && tok->scope()->isExecutable()) { + const Scope* fscope = tok->scope(); + while (fscope && !fscope->function) + fscope = fscope->nestedIn; + const Scope* defScope = fscope && fscope->function->tokenDef ? fscope->function->tokenDef->scope() : nullptr; + if (defScope && defScope->isClassOrStruct()) { + ValueType vt(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::RECORD, 1); + vt.typeScope = defScope; + if (fscope->function->isConst()) + vt.constness = 1; + setValueType(tok, vt); + } } } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index e2add4155..3ae225006 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -473,6 +473,7 @@ private: TEST_CASE(valueType1); TEST_CASE(valueType2); + TEST_CASE(valueTypeThis); TEST_CASE(variadic1); // #7453 TEST_CASE(variadic2); // #7649 @@ -7923,6 +7924,11 @@ private: } } + void valueTypeThis() { + ASSERT_EQUALS("C *", typeOf("class C { C() { *this = 0; } };", "this")); + ASSERT_EQUALS("const C *", typeOf("class C { void foo() const; }; void C::foo() const { *this = 0; }", "this")); + } + void variadic1() { // #7453 { GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"