CheckInternal: Check that emplace is not used

This commit is contained in:
Daniel Marjamäki 2018-04-14 19:43:57 +02:00
parent e95ff8c7b6
commit 0a83c6b173
2 changed files with 17 additions and 0 deletions

13
lib/checkinternal.cpp Normal file → Executable file
View File

@ -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",

4
lib/checkinternal.h Normal file → Executable file
View File

@ -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);