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
…7026)

(cherry picked from c307483)
  • Loading branch information
danmar committed Nov 26, 2024
1 parent 589cf59 commit 196f257
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5716,6 +5716,17 @@ 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() ||
(func->isVariadic() && args >= (func->minArgCount() - 1)) ||
(args < func->argCount() && args >= func->minArgCount())) {
Expand Down
20 changes: 20 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(findFunction55); // #13004
TEST_CASE(findFunction56);
TEST_CASE(findFunctionRef1);
TEST_CASE(findFunctionRef2); // #13328
TEST_CASE(findFunctionContainer);
TEST_CASE(findFunctionExternC);
TEST_CASE(findFunctionGlobalScope); // ::foo
Expand Down Expand Up @@ -8368,6 +8369,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 196f257

Please sign in to comment.