diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 32ac35aff..e36082fe0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9573,7 +9573,7 @@ void Tokenizer::simplifyNamespaceStd() for (const Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) { bool insert = false; - if (Token::Match(tok, "%var% (") && !Token::Match(tok->previous(), ".|::") && stdFunctions.find(tok->str()) != stdFunctions.end()) + if (Token::Match(tok, "%var% (") && !Token::Match(tok->previous(), ".|::") && !Token::Match(tok->linkAt(1)->next(), "%var%|{") && stdFunctions.find(tok->str()) != stdFunctions.end()) insert = true; else if (Token::Match(tok, "%var% <") && !Token::Match(tok->previous(), ".|::") && stdTemplates.find(tok->str()) != stdTemplates.end()) insert = true; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 82c771066..1cae4463b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7795,6 +7795,20 @@ private: static const char expected13[] = "try { }\n" "catch ( std :: exception & exception ) { }"; ASSERT_EQUALS(expected13, tokenizeAndStringify(code13, false)); + + // #5773 (Don't prepend 'std ::' to function definitions) + static const char code14[] = "using namespace std;\n" + "class C {\n" + " void search() {}\n" + " void search() const {}\n" + " void search() THROW_MACRO {}\n" + "};"; + static const char expected14[] = "class C {\n" + "void search ( ) { }\n" + "void search ( ) const { }\n" + "void search ( ) THROW_MACRO { }\n" + "} ;"; + ASSERT_EQUALS(expected14, tokenizeAndStringify(code14, false)); } void microsoftMFC() {