diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c66def4f0..7bf490f0c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10169,11 +10169,14 @@ void Tokenizer::simplifyNamespaceAliases() int scope = 0; for (Token *tok = list.front(); tok; tok = tok->next()) { + bool isPrev{}; if (tok->str() == "{") scope++; else if (tok->str() == "}") scope--; - else if (Token::Match(tok, "namespace %name% =")) { + else if (Token::Match(tok, "namespace %name% =") || (isPrev = Token::Match(tok->previous(), "namespace %name% ="))) { + if (isPrev) + tok = tok->previous(); const std::string name(tok->next()->str()); Token * tokNameStart = tok->tokAt(3); Token * tokNameEnd = tokNameStart; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index b425e28a2..1db88f2ba 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1455,6 +1455,9 @@ private: "}" "namespace AB = A::B;" //duplicate declaration "}")); + ASSERT_EQUALS(";", + tok("namespace p = boost::python;\n" + "namespace np = boost::numpy;\n")); // redeclared nested namespace aliases TODO_ASSERT_EQUALS("namespace A { namespace B { void foo ( ) { bar ( A :: B :: ab ( ) ) ; { baz ( A :: a ( ) ) ; } bar ( A :: B :: ab ( ) ) ; } } }",