Skip to content

Commit

Permalink
Fix #13328 (SymbolDatabase: does not select l-value method properly) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar authored Nov 20, 2024
1 parent 8f40b82 commit c307483
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5716,6 +5716,15 @@ const Function* Scope::findFunction(const Token *tok, bool requireConst, Referen
const Function *func = it->second;
if (ref == Reference::LValue && func->hasRvalRefQualifier())
continue;
if (ref == Reference::None && func->hasRvalRefQualifier()) {
if (Token::simpleMatch(tok->astParent(), ".")) {
const Token* obj = tok->astParent()->astOperand1();
while (obj && obj->str() == "[")
obj = obj->astOperand1();
if (!obj || obj->isName())
continue;
}
}
if (func->isDestructor() && !Token::simpleMatch(tok->tokAt(-1), "~"))
continue;
if (!isCall || args == func->argCount() ||
Expand Down
20 changes: 20 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(findFunction56);
TEST_CASE(findFunction57);
TEST_CASE(findFunctionRef1);
TEST_CASE(findFunctionRef2); // #13328
TEST_CASE(findFunctionContainer);
TEST_CASE(findFunctionExternC);
TEST_CASE(findFunctionGlobalScope); // ::foo
Expand Down Expand Up @@ -8393,6 +8394,25 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS(2, f->function()->tokenDef->linenr());
}

void findFunctionRef2() {
GET_SYMBOL_DB("struct X {\n"
" const int& foo() const &;\n" // <- this function is called
" int foo() &&;\n"
"}\n"
"\n"
"void foo() {\n"
" X x;\n"
" x.foo();\n"
"}\n");
const Token* x = Token::findsimplematch(tokenizer.tokens(), "x . foo ( ) ;");
ASSERT(x);
const Token* f = x->tokAt(2);
ASSERT(f);
ASSERT(f->function());
ASSERT(f->function()->tokenDef);
ASSERT_EQUALS(2, f->function()->tokenDef->linenr());
}

void findFunctionContainer() {
{
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
Expand Down

0 comments on commit c307483

Please sign in to comment.