Fix #9385 ("debug: Executable scope 'func' with unknown function" with parameter in member function) (#2235)

This commit is contained in:
IOBYTE 2019-10-03 15:13:03 -04:00 committed by Daniel Marjamäki
parent 7e850e3e4b
commit 50d82763fc
2 changed files with 52 additions and 0 deletions

View File

@ -2007,6 +2007,22 @@ bool Tokenizer::simplifyUsing()
continue;
}
// check for member function
if (Token::Match(tok1->tokAt(-2), ":: %name% (") && isFunctionHead(tok1, "{")) {
std::string qualification;
const Token *qualTok = tok1->tokAt(-3);
while (Token::Match(qualTok, "%type% ::")) {
if (!qualification.empty())
qualification = " :: " + qualification;
qualification = qualTok->str() + qualification;
qualTok = qualTok->tokAt(-2);
}
if (!scope1.empty())
scope1 += " :: ";
scope1 += qualification;
}
if (!usingMatch(nameToken, scope, &tok1, scope1, scopeList1))
continue;

View File

@ -66,6 +66,7 @@ private:
TEST_CASE(simplifyUsing9042);
TEST_CASE(simplifyUsing9191);
TEST_CASE(simplifyUsing9381);
TEST_CASE(simplifyUsing9385);
}
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
@ -549,6 +550,41 @@ private:
ASSERT_EQUALS(exp, tok(code, false));
}
void simplifyUsing9385() {
{
const char code[] = "class A {\n"
"public:\n"
" using Foo = Bar;\n"
" void func(Foo foo);\n"
"};\n"
"void A::func(Foo) { }";
const char exp[] = "class A { "
"public: "
"void func ( Bar foo ) ; "
"} ; "
"void A :: func ( Bar ) { }";
ASSERT_EQUALS(exp, tok(code, false));
}
{
const char code[] = "class A {\n"
"public:\n"
" struct B {\n"
" using Foo = Bar;\n"
" void func(Foo foo);\n"
" };\n"
"};\n"
"void A::B::func(Foo) { }";
const char exp[] = "class A { "
"public: "
"struct B { "
"void func ( Bar foo ) ; "
"} ; "
"} ; "
"void A :: B :: func ( Bar ) { }";
ASSERT_EQUALS(exp, tok(code, false));
}
}
};
REGISTER_TEST(TestSimplifyUsing)