diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index cf91eabde25..100b80240aa 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -571,6 +571,8 @@ void Tokenizer::simplifyUsingToTypedef() while (Token::Match(endtok, ":: %name%")) endtok = endtok->tokAt(2); if (endtok && endtok->str() == ";") { + if (endtok->strAt(-1) == endtok->strAt(-3)) + continue; tok->next()->str("typedef"); endtok = endtok->previous(); endtok->insertToken(endtok->str()); diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 78898ccbc62..d6c3762fbad 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -70,6 +70,7 @@ class TestSimplifyUsing : public TestFixture { TEST_CASE(simplifyUsing28); TEST_CASE(simplifyUsing29); TEST_CASE(simplifyUsing30); + TEST_CASE(simplifyUsing31); TEST_CASE(simplifyUsing8970); TEST_CASE(simplifyUsing8971); @@ -754,6 +755,33 @@ class TestSimplifyUsing : public TestFixture { } } + void simplifyUsing31() { // #11899 + const char code[] = "struct B {\n" + " B();\n" + " void f();\n" + "};\n" + "struct D : B {\n" + " using B::B;\n" + " void g() {\n" + " B::f();\n" + " }\n" + " B b;\n" + "};\n"; + const char expected[] = "struct B { " + "B ( ) ; " + "void f ( ) ; " + "} ; " + "struct D : B { " + "using B = B :: B ; " + "void g ( ) { " + "B :: f ( ) ; " + "} " + "B b ; " + "} ;"; + ASSERT_EQUALS(expected, tok(code, Platform::Type::Native, /*debugwarnings*/ true)); + ASSERT_EQUALS("", errout_str()); + } + void simplifyUsing8970() { const char code[] = "using V = std::vector;\n" "struct A {\n"