Fixed #7887 (User function 'search' is wrongly mixed with std function)
This commit is contained in:
parent
c048bd45f6
commit
7eb5ebe17e
|
@ -9463,15 +9463,27 @@ void Tokenizer::simplifyNamespaceStd()
|
|||
|
||||
const bool isCPP11 = mSettings->standards.cpp == Standards::CPP11;
|
||||
|
||||
std::set<std::string> userFunctions;
|
||||
|
||||
for (const Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) {
|
||||
bool insert = false;
|
||||
if (Token::Match(tok, "enum class|struct| %name%| :|{")) { // Don't replace within enum definitions
|
||||
skipEnumBody(&tok);
|
||||
}
|
||||
if (!Token::Match(tok->previous(), ".|::")) {
|
||||
if (Token::Match(tok, "%name% (") && !isFunctionHead(tok->next(),"{") && stdFunctions.find(tok->str()) != stdFunctions.end())
|
||||
if (Token::Match(tok, "%name% (")) {
|
||||
if (isFunctionHead(tok->next(), "{"))
|
||||
userFunctions.insert(tok->str());
|
||||
else if (isFunctionHead(tok->next(), ";")) {
|
||||
const Token *start = tok;
|
||||
while (Token::Match(start->previous(), "%type%|*|&"))
|
||||
start = start->previous();
|
||||
if (start != tok && start->isName() && (!start->previous() || Token::Match(start->previous(), "[;{}]")))
|
||||
userFunctions.insert(tok->str());
|
||||
}
|
||||
if (userFunctions.find(tok->str()) == userFunctions.end() && stdFunctions.find(tok->str()) != stdFunctions.end())
|
||||
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;
|
||||
else if (tok->isName() && !tok->varId() && !Token::Match(tok->next(), "(|<") && stdTypes.find(tok->str()) != stdTypes.end())
|
||||
insert = true;
|
||||
|
|
|
@ -5633,6 +5633,11 @@ private:
|
|||
"void search() {}";
|
||||
ASSERT_EQUALS("void search ( ) { }", tokenizeAndStringify(code, false));
|
||||
|
||||
code = "using namespace std;\n"
|
||||
"void search();\n"
|
||||
"void dostuff() { search(); }";
|
||||
ASSERT_EQUALS("void search ( ) ;\nvoid dostuff ( ) { search ( ) ; }", tokenizeAndStringify(code, false));
|
||||
|
||||
code = "using namespace std;\n"
|
||||
"void foo() {map(a, b); }"; // That's obviously not std::map<>
|
||||
ASSERT_EQUALS("void foo ( ) { map ( a , b ) ; }", tokenizeAndStringify(code, false));
|
||||
|
|
Loading…
Reference in New Issue