Modernize: make use of 'nullptr' and added a rule-file for finding non-nullptr (zero) initializations.
This commit is contained in:
parent
c1eb71e84d
commit
0e575ce12c
|
@ -339,8 +339,8 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt()
|
||||||
if (!tok->isComparisonOp())
|
if (!tok->isComparisonOp())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const Token* numTok = 0;
|
const Token* numTok = nullptr;
|
||||||
const Token* boolExpr = 0;
|
const Token* boolExpr = nullptr;
|
||||||
bool numInRhs;
|
bool numInRhs;
|
||||||
if (astIsBool(tok->astOperand1())) {
|
if (astIsBool(tok->astOperand1())) {
|
||||||
boolExpr = tok->astOperand1();
|
boolExpr = tok->astOperand1();
|
||||||
|
|
|
@ -318,7 +318,7 @@ void CheckClass::copyconstructors()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<const Token*> copiedVars;
|
std::set<const Token*> copiedVars;
|
||||||
const Token* copyCtor = 0;
|
const Token* copyCtor = nullptr;
|
||||||
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
||||||
if (func->type == Function::eCopyConstructor) {
|
if (func->type == Function::eCopyConstructor) {
|
||||||
copyCtor = func->tokenDef;
|
copyCtor = func->tokenDef;
|
||||||
|
|
|
@ -180,7 +180,7 @@ void CheckIO::checkFileUsage()
|
||||||
}
|
}
|
||||||
} else if (Token::Match(tok, "%name% (") && tok->previous() && (!tok->previous()->isName() || Token::Match(tok->previous(), "return|throw"))) {
|
} else if (Token::Match(tok, "%name% (") && tok->previous() && (!tok->previous()->isName() || Token::Match(tok->previous(), "return|throw"))) {
|
||||||
std::string mode;
|
std::string mode;
|
||||||
const Token* fileTok = 0;
|
const Token* fileTok = nullptr;
|
||||||
Filepointer::Operation operation = Filepointer::NONE;
|
Filepointer::Operation operation = Filepointer::NONE;
|
||||||
|
|
||||||
if ((tok->str() == "fopen" || tok->str() == "freopen" || tok->str() == "tmpfile" ||
|
if ((tok->str() == "fopen" || tok->str() == "freopen" || tok->str() == "tmpfile" ||
|
||||||
|
@ -508,8 +508,8 @@ void CheckIO::checkWrongPrintfScanfArguments()
|
||||||
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
|
||||||
if (!tok->isName()) continue;
|
if (!tok->isName()) continue;
|
||||||
|
|
||||||
const Token* argListTok = 0; // Points to first va_list argument
|
const Token* argListTok = nullptr; // Points to first va_list argument
|
||||||
const Token* formatStringTok = 0; // Points to format string token
|
const Token* formatStringTok = nullptr; // Points to format string token
|
||||||
|
|
||||||
bool scan = false;
|
bool scan = false;
|
||||||
bool scanf_s = false;
|
bool scanf_s = false;
|
||||||
|
|
|
@ -84,7 +84,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Token::Match(&tok, "printf|sprintf|snprintf|fprintf|fnprintf|scanf|sscanf|fscanf|wprintf|swprintf|fwprintf|wscanf|swscanf|fwscanf")) {
|
if (Token::Match(&tok, "printf|sprintf|snprintf|fprintf|fnprintf|scanf|sscanf|fscanf|wprintf|swprintf|fwprintf|wscanf|swscanf|fwscanf")) {
|
||||||
const Token* argListTok = 0; // Points to first va_list argument
|
const Token* argListTok = nullptr; // Points to first va_list argument
|
||||||
std::string formatString;
|
std::string formatString;
|
||||||
bool scan = Token::Match(&tok, "scanf|sscanf|fscanf|wscanf|swscanf|fwscanf");
|
bool scan = Token::Match(&tok, "scanf|sscanf|fscanf|wscanf|swscanf|fwscanf");
|
||||||
|
|
||||||
|
|
|
@ -994,8 +994,8 @@ void CheckOther::checkUnreachableCode()
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
const Scope * scope = symbolDatabase->functionScopes[i];
|
||||||
|
|
||||||
for (const Token* tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
for (const Token* tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
|
||||||
const Token* secondBreak = 0;
|
const Token* secondBreak = nullptr;
|
||||||
const Token* labelName = 0;
|
const Token* labelName = nullptr;
|
||||||
if (tok->link() && Token::Match(tok, "(|[|<"))
|
if (tok->link() && Token::Match(tok, "(|[|<"))
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
else if (Token::Match(tok, "break|continue ;"))
|
else if (Token::Match(tok, "break|continue ;"))
|
||||||
|
@ -1177,7 +1177,7 @@ bool CheckOther::checkInnerScope(const Token *tok, const Variable* var, bool& us
|
||||||
const Scope* scope = tok->next()->scope();
|
const Scope* scope = tok->next()->scope();
|
||||||
bool loopVariable = scope->type == Scope::eFor || scope->type == Scope::eWhile || scope->type == Scope::eDo;
|
bool loopVariable = scope->type == Scope::eFor || scope->type == Scope::eWhile || scope->type == Scope::eDo;
|
||||||
bool noContinue = true;
|
bool noContinue = true;
|
||||||
const Token* forHeadEnd = 0;
|
const Token* forHeadEnd = nullptr;
|
||||||
const Token* end = tok->link();
|
const Token* end = tok->link();
|
||||||
if (scope->type == Scope::eUnconditional && (tok->strAt(-1) == ")" || tok->previous()->isName())) // Might be an unknown macro like BOOST_FOREACH
|
if (scope->type == Scope::eUnconditional && (tok->strAt(-1) == ")" || tok->previous()->isName())) // Might be an unknown macro like BOOST_FOREACH
|
||||||
loopVariable = true;
|
loopVariable = true;
|
||||||
|
|
|
@ -4840,7 +4840,7 @@ bool Tokenizer::simplifyConditions()
|
||||||
bool Tokenizer::simplifyConstTernaryOp()
|
bool Tokenizer::simplifyConstTernaryOp()
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
const Token *templateParameterEnd = 0; // The end of the current template parameter list, if any
|
const Token *templateParameterEnd = nullptr; // The end of the current template parameter list, if any
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (tok->str() == "<" && TemplateSimplifier::templateParameters(tok))
|
if (tok->str() == "<" && TemplateSimplifier::templateParameters(tok))
|
||||||
templateParameterEnd = tok->findClosingBracket();
|
templateParameterEnd = tok->findClosingBracket();
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<rule version="1">
|
||||||
|
<tokenlist>raw</tokenlist> <!-- playground: https://regex101.com/r/vGfGSA/1 -->
|
||||||
|
<pattern><![CDATA[(\b\w+\b) \* (\b\w+\b) = 0 ;]]></pattern>
|
||||||
|
<message>
|
||||||
|
<id>modernizeUseNullPtr</id>
|
||||||
|
<severity>style</severity>
|
||||||
|
<summary>Prefer to use a 'nullptr' instead of initialize a pointer with 0.</summary>
|
||||||
|
</message>
|
||||||
|
</rule>
|
Loading…
Reference in New Issue