From 4ba00d0694853b8420b1bc3a6a66ba3e04569986 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Wed, 2 Oct 2019 02:11:04 -0400 Subject: [PATCH] Fix #9381 (alias in namespace not replaced in method declaration) (#2232) --- lib/tokenize.cpp | 1 + test/testsimplifyusing.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9af091fc1..2fcb3c762 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1855,6 +1855,7 @@ namespace { std::string newScope1 = scope1; // scopes didn't match so try higher scopes + index = newScope1.size(); while (!newScope1.empty()) { std::string::size_type separator = newScope1.rfind(" :: ", index - 1); if (separator != std::string::npos) diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 2372959bc..1822047f3 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -65,6 +65,7 @@ private: TEST_CASE(simplifyUsing9040); TEST_CASE(simplifyUsing9042); TEST_CASE(simplifyUsing9191); + TEST_CASE(simplifyUsing9381); } std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) { @@ -524,6 +525,30 @@ private: ASSERT_EQUALS(exp, tok(code, false)); } + void simplifyUsing9381() { + const char code[] = "namespace ns {\n" + " class Result;\n" + " using UniqueResultPtr = std::unique_ptr;\n" + " class A {\n" + " public:\n" + " void func(UniqueResultPtr);\n" + " };\n" + " void A::func(UniqueResultPtr) {\n" + " }\n" + "}"; + const char exp[] = "namespace ns { " + "class Result ; " + "class A { " + "public: " + "void func ( std :: unique_ptr < Result > ) ; " + "} ; " + "void A :: func ( std :: unique_ptr < Result > ) { " + "} " + "}"; + + ASSERT_EQUALS(exp, tok(code, false)); + } + }; REGISTER_TEST(TestSimplifyUsing)