diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 08c700794c7..cf91eabde25 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -792,7 +792,8 @@ namespace { } if (Token::Match(tok, "%name% ::")) { - if (Token::Match(mRangeType.first, "const| struct|class|union|enum %name% %name%|{")) { + if (Token::Match(mRangeType.first, "const| struct|class|union|enum %name% %name%|{") || + Token::Match(mRangeType.first, "%name% %name% ;")) { tok->originalName(tok->str()); tok->str(mRangeType.second->strAt(-1)); } else { diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 76f53b0072f..611f9fd36fd 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -3686,6 +3686,19 @@ class TestSimplifyTypedef : public TestFixture { "} " "}"; ASSERT_EQUALS(exp3, tok(code3)); + + const char code4[] = "struct A { static const int i = 1; };\n" // #12947 + "typedef A B;\n" + "int f() {\n" + " return B::i;\n" + "}\n"; + const char exp4[] = "struct A { " + "static const int i = 1 ; " + "} ; " + "int f ( ) { " + "return A :: i ; " + "}"; + ASSERT_EQUALS(exp4, tok(code4)); } void simplifyTypedefFunction1() {