Skip to content

Commit

Permalink
Fix syntaxError with using namespace ::std (f'up to #8454) (#6100)
Browse files Browse the repository at this point in the history
Why do `%type%` and `%name%` match keywords?
  • Loading branch information
chrchr-github authored Mar 10, 2024
1 parent 866619c commit f9f3fe0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,9 @@ bool Tokenizer::simplifyUsing()
for (Token* tok = list.front(); tok; tok = tok->next()) {
if (!Token::Match(tok, "using ::| %name% ::"))
continue;
const Token* ns = tok->tokAt(tok->strAt(1) == "::" ? 2 : 1);
if (ns->isKeyword())
continue;
Token* end = tok->tokAt(3);
while (end && !Token::Match(end, "[;,]")) {
if (end->str() == "<" && end->link()) // skip template args
Expand Down
12 changes: 12 additions & 0 deletions test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,18 @@ class TestSimplifyUsing : public TestFixture {
ASSERT_EQUALS(expected, tok(code, Platform::Type::Native, /*debugwarnings*/ true));
ASSERT_EQUALS("", errout.str());
}
{
const char code[] = "using namespace ::std;\n"
"void f(const char* c) {\n"
" cout << std::string(c) << \"abc\";\n"
"}\n";
const char expected[] = "using namespace :: std ; " // TODO: simplify cout?
"void f ( const char * c ) { "
"cout << std :: string ( c ) << \"abc\" ; "
"}";
ASSERT_EQUALS(expected, tok(code, Platform::Type::Native, /*debugwarnings*/ true));
ASSERT_EQUALS("", errout.str());
}
}

void simplifyUsing8970() {
Expand Down

0 comments on commit f9f3fe0

Please sign in to comment.