Fix #11629 debug: Scope::checkVariable found variable 'np' with varid 0. (#4915)

This commit is contained in:
chrchr-github 2023-04-03 15:41:19 +02:00 committed by GitHub
parent a336048d14
commit b2b0962067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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;

View File

@ -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 ( ) ) ; } } }",