Skip to content

Commit

Permalink
Fix syntaxError with using namespace ::std
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Mar 8, 2024
1 parent 49897e6 commit b55a1ce
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 b55a1ce

Please sign in to comment.