diff --git a/cfg/std.cfg b/cfg/std.cfg index b32b4cae74a..ab2516eee58 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -6645,6 +6645,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun false + diff --git a/lib/library.cpp b/lib/library.cpp index f1058c7883a..4bb2aa94879 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1010,8 +1010,12 @@ std::string Library::getFunctionName(const Token *ftok) const if (ftok->astParent()) { bool error = false; const Token * tok = ftok->astParent()->isUnaryOp("&") ? ftok->astParent()->astOperand1() : ftok->next()->astOperand1(); - const std::string ret = getFunctionName(tok, error); - return error ? std::string() : ret; + std::string ret = getFunctionName(tok, error); + if (error) + return {}; + if (startsWith(ret, "::")) + ret.erase(0, 2); + return ret; } // Lookup function name without using AST.. diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 03b31da4bcc..6d4e9e6989d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9664,6 +9664,7 @@ void Tokenizer::simplifyNamespaceStd() continue; if (Token::Match(tok->previous(), ".|::|namespace")) continue; + const Library::Container* ctr{}; if (Token::simpleMatch(tok->next(), "(")) { if (isFunctionHead(tok->next(), "{")) userFunctions.insert(tok->str()); @@ -9681,7 +9682,7 @@ void Tokenizer::simplifyNamespaceStd() insert = true; else if (mSettings->library.hasAnyTypeCheck("std::" + tok->str()) || mSettings->library.podtype("std::" + tok->str()) || - mSettings->library.detectContainerOrIterator(tok, nullptr, /*withoutStd*/ true)) + ((ctr = mSettings->library.detectContainerOrIterator(tok, nullptr, /*withoutStd*/ true)) != nullptr && startsWith(ctr->startPattern, "std ::"))) insert = true; if (insert) { diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index 2bef064a983..6a669953a70 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -71,6 +71,16 @@ bool QString7(QString s, const QString& l) { return l.startsWith(s); } +namespace // #12355 +{ + using namespace std; + QString QString_std(QString s) + { + s.replace("abc", "def"); + return s; + } +} + void QByteArray1(QByteArray byteArrayArg) { for (int i = 0; i <= byteArrayArg.size(); ++i) { diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 28279b77a6f..834ea0caa25 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -4860,3 +4860,9 @@ void std_vector_data_arithmetic() buf.resize(1); memcpy(buf.data() + 0, "", 1); } + +std::string global_scope_std() // #12355 +{ + ::std::stringstream ss; + return ss.str(); +} \ No newline at end of file