Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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