diff --git a/lib/checkinternal.cpp b/lib/checkinternal.cpp old mode 100644 new mode 100755 index bdce41a8e..e8ef04d23 --- a/lib/checkinternal.cpp +++ b/lib/checkinternal.cpp @@ -347,6 +347,19 @@ void CheckInternal::checkExtraWhitespace() } } +void CheckInternal::checkStlUsage() +{ + const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); + for (const Scope *scope : symbolDatabase->functionScopes) { + for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + if (Token::simpleMatch(tok, ". emplace (")) + reportError(tok, Severity::error, "internalStlUsage", "The 'emplace' function shall be avoided for now. 'emplace_back' is fine"); + //if (Token::simpleMatch(tok, ". back ( )") && tok->astOperand1() && tok->astOperand1()->valueType() && tok->astOperand1()->valueType()->container && Token::simpleMatch(tok->astOperand1()->valueType()->container, "std :: string")) + // reportError(tok, Severity::error, "internalStlUsage", "The 'std::string::back()' function shall be avoided for now."); + } + } +} + void CheckInternal::multiComparePatternError(const Token* tok, const std::string& pattern, const std::string &funcname) { reportError(tok, Severity::error, "multiComparePatternError", diff --git a/lib/checkinternal.h b/lib/checkinternal.h old mode 100644 new mode 100755 index b1d062518..b582139e8 --- a/lib/checkinternal.h +++ b/lib/checkinternal.h @@ -57,6 +57,7 @@ public: checkInternal.checkRedundantNextPrevious(); checkInternal.checkExtraWhitespace(); checkInternal.checkRedundantTokCheck(); + checkInternal.checkStlUsage(); } /** @brief %Check if a simple pattern is used inside Token::Match or Token::findmatch */ @@ -79,6 +80,9 @@ public: /** @brief %Check if there is a redundant check for none-nullness of parameter before Match functions, such as (tok && Token::Match(tok, "foo")) */ void checkRedundantTokCheck(); + + /** @brief Try to avoid some new functions that are not fully supported in Linux */ + void checkStlUsage(); private: void multiComparePatternError(const Token *tok, const std::string &pattern, const std::string &funcname); void simplePatternError(const Token *tok, const std::string &pattern, const std::string &funcname);