diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 35ca38299..4740fa3b8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 1822047f3..d9458cc2f 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -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)