Partial fix for #7887, Improved tokenizer simplification of 'using namespace std;' - do not simplify user functions

This commit is contained in:
Daniel Marjamäki 2018-10-10 14:28:53 +02:00
parent f6f4116389
commit 25cbfe27cf
2 changed files with 7 additions and 1 deletions

View File

@ -9469,7 +9469,7 @@ void Tokenizer::simplifyNamespaceStd()
skipEnumBody(&tok); skipEnumBody(&tok);
} }
if (!Token::Match(tok->previous(), ".|::")) { if (!Token::Match(tok->previous(), ".|::")) {
if (Token::Match(tok, "%name% (") && !Token::Match(tok->linkAt(1)->next(), "%name%|{") && stdFunctions.find(tok->str()) != stdFunctions.end()) if (Token::Match(tok, "%name% (") && !isFunctionHead(tok->next(),"{") && stdFunctions.find(tok->str()) != stdFunctions.end())
insert = true; insert = true;
else if (Token::Match(tok, "%name% <") && stdTemplates.find(tok->str()) != stdTemplates.end()) else if (Token::Match(tok, "%name% <") && stdTemplates.find(tok->str()) != stdTemplates.end())
insert = true; insert = true;

View File

@ -5612,6 +5612,8 @@ private:
} }
void simplifyNamespaceStd() { void simplifyNamespaceStd() {
const char *code;
static const char code1[] = "map<foo, bar> m;"; // namespace std is not used static const char code1[] = "map<foo, bar> m;"; // namespace std is not used
ASSERT_EQUALS("map < foo , bar > m ;", tokenizeAndStringify(code1, false)); ASSERT_EQUALS("map < foo , bar > m ;", tokenizeAndStringify(code1, false));
@ -5627,6 +5629,10 @@ private:
"void foo() {swap(a, b); }"; "void foo() {swap(a, b); }";
ASSERT_EQUALS("void foo ( ) { std :: swap ( a , b ) ; }", tokenizeAndStringify(code4, false)); ASSERT_EQUALS("void foo ( ) { std :: swap ( a , b ) ; }", tokenizeAndStringify(code4, false));
code = "using namespace std;\n"
"void search() {}";
ASSERT_EQUALS("void search ( ) { }", tokenizeAndStringify(code, false));
static const char code5[] = "using namespace std;\n" static const char code5[] = "using namespace std;\n"
"void foo() {map(a, b); }"; // That's obviously not std::map<> "void foo() {map(a, b); }"; // That's obviously not std::map<>
ASSERT_EQUALS("void foo ( ) { map ( a , b ) ; }", tokenizeAndStringify(code5, false)); ASSERT_EQUALS("void foo ( ) { map ( a , b ) ; }", tokenizeAndStringify(code5, false));