@@ -447,6 +447,7 @@ class TestSymbolDatabase : public TestFixture {
447447 TEST_CASE (findFunction48);
448448 TEST_CASE (findFunction49); // #11888
449449 TEST_CASE (findFunction50); // #11904 - method with same name and arguments in derived class
450+ TEST_CASE (findFunction51); // #11975 - method with same name in derived class
450451 TEST_CASE (findFunctionContainer);
451452 TEST_CASE (findFunctionExternC);
452453 TEST_CASE (findFunctionGlobalScope); // ::foo
@@ -7372,6 +7373,67 @@ class TestSymbolDatabase : public TestFixture {
73727373 }
73737374 }
73747375
7376+ void findFunction51 () {
7377+ // Both A and B defines the method test but with different arguments.
7378+ // The call to test in B should match the method in B. The match is close enough.
7379+ {
7380+ GET_SYMBOL_DB (" class A {\n "
7381+ " public:\n "
7382+ " void test(bool a = true);\n "
7383+ " };\n "
7384+ " \n "
7385+ " class B : public A {\n "
7386+ " public:\n "
7387+ " B(): b_obj(this) { b_obj->test(\" 1\" ); }\n "
7388+ " void test(const std::string& str_obj);\n "
7389+ " B* b_obj;\n "
7390+ " };" );
7391+ const Token* call = Token::findsimplematch (tokenizer.tokens (), " test ( \" 1\" ) ;" );
7392+ ASSERT (call);
7393+ ASSERT (call->function ());
7394+ ASSERT (call->function ()->tokenDef );
7395+ ASSERT_EQUALS (9 , call->function ()->tokenDef ->linenr ());
7396+ }
7397+ {
7398+ GET_SYMBOL_DB (" struct STR { STR(const char * p); };\n "
7399+ " class A {\n "
7400+ " public:\n "
7401+ " void test(bool a = true);\n "
7402+ " };\n "
7403+ " \n "
7404+ " class B : public A {\n "
7405+ " public:\n "
7406+ " B(): b_obj(this) { b_obj->test(\" 1\" ); }\n "
7407+ " void test(const STR& str_obj);\n "
7408+ " B* b_obj;\n "
7409+ " };" );
7410+ const Token* call = Token::findsimplematch (tokenizer.tokens (), " test ( \" 1\" ) ;" );
7411+ ASSERT (call);
7412+ ASSERT (call->function ());
7413+ ASSERT (call->function ()->tokenDef );
7414+ ASSERT_EQUALS (10 , call->function ()->tokenDef ->linenr ());
7415+ }
7416+ {
7417+ GET_SYMBOL_DB (" struct STR { STR(const char * p); };\n "
7418+ " class A {\n "
7419+ " public:\n "
7420+ " void test(bool a = true, int b = 0);\n "
7421+ " };\n "
7422+ " \n "
7423+ " class B : public A {\n "
7424+ " public:\n "
7425+ " B(): b_obj(this) { b_obj->test(\" 1\" ); }\n "
7426+ " void test(const STR& str_obj);\n "
7427+ " B* b_obj;\n "
7428+ " };" );
7429+ const Token* call = Token::findsimplematch (tokenizer.tokens (), " test ( \" 1\" ) ;" );
7430+ ASSERT (call);
7431+ ASSERT (call->function ());
7432+ ASSERT (call->function ()->tokenDef );
7433+ ASSERT_EQUALS (10 , call->function ()->tokenDef ->linenr ());
7434+ }
7435+ }
7436+
73757437 void findFunctionContainer () {
73767438 {
73777439 GET_SYMBOL_DB (" void dostuff(std::vector<int> v);\n "
0 commit comments