fix #10075 (namespace alias changes variable name) (#3020)

This commit is contained in:
IOBYTE 2021-01-06 11:30:11 -05:00 committed by GitHub
parent c085151eb0
commit cb02628c7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View File

@ -12019,12 +12019,14 @@ void Tokenizer::simplifyNamespaceAliases()
}
}
tok2->str(tokNameStart->str());
Token * tok3 = tokNameStart;
while (tok3 != tokNameEnd) {
tok2->insertToken(tok3->next()->str());
tok2 = tok2->next();
tok3 = tok3->next();
if (tok2->strAt(1) == "::") {
tok2->str(tokNameStart->str());
Token * tok3 = tokNameStart;
while (tok3 != tokNameEnd) {
tok2->insertToken(tok3->next()->str());
tok2 = tok2->next();
tok3 = tok3->next();
}
}
}
tok2 = tok2->next();

View File

@ -4973,6 +4973,27 @@ private:
"}"
"namespace AB = A::B;" //duplicate declaration
"}"));
// variable and namespace alias with same name
ASSERT_EQUALS("namespace external { namespace ns { "
"class A { "
"public: "
"static void f ( const std :: string & json ) ; "
"} ; "
"} } "
"namespace external { namespace ns { "
"void A :: f ( const std :: string & json ) { } "
"} }",
tok("namespace external::ns {"
" class A {"
" public:"
" static void f(const std::string& json);"
" };"
"}"
"namespace json = rapidjson;"
"namespace external::ns {"
" void A::f(const std::string& json) { }"
"}"));
}
};