diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 7a1bf4e28..0d9b6b78b 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1902,7 +1902,7 @@ static bool functionModifiesArguments(const Function* f) bool isConstFunctionCall(const Token* ftok, const Library& library) { - if (isSizeOfEtc(ftok)) + if (isUnevaluated(ftok)) return true; if (!Token::Match(ftok, "%name% (")) return false; @@ -3382,7 +3382,7 @@ bool isGlobalData(const Token *expr, bool cpp) return globalData || !var; } -bool isSizeOfEtc(const Token *tok) +bool isUnevaluated(const Token *tok) { - return Token::Match(tok, "sizeof|typeof|offsetof|decltype|__typeof__ ("); + return Token::Match(tok, "alignof|_Alignof|_alignof|__alignof|__alignof__|decltype|offsetof|sizeof|typeid|typeof|__typeof__ ("); } diff --git a/lib/astutils.h b/lib/astutils.h index c34bdd81b..fdcc713d7 100644 --- a/lib/astutils.h +++ b/lib/astutils.h @@ -427,6 +427,6 @@ CPPCHECKLIB bool isNullOperand(const Token *expr); bool isGlobalData(const Token *expr, bool cpp); -bool isSizeOfEtc(const Token *tok); +bool isUnevaluated(const Token *tok); #endif // astutilsH diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 42c66bf51..3e767ce7a 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -150,11 +150,6 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown) const return isPointerDeRef(tok, unknown, mSettings); } -static bool isUnevaluatedOperator(const Token* tok) -{ - return Token::Match(tok, "sizeof|decltype|typeid|typeof|alignof|_Alignof|_alignof|__alignof|__alignof__ ("); -} - bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Settings *settings) { unknown = false; @@ -192,7 +187,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Set // Dereferencing pointer.. const Token* grandParent = parent->astParent(); - if (parent->isUnaryOp("*") && !(grandParent && isUnevaluatedOperator(grandParent->previous()))) { + if (parent->isUnaryOp("*") && !(grandParent && isUnevaluated(grandParent->previous()))) { // declaration of function pointer if (tok->variable() && tok->variable()->nameToken() == tok) return false; @@ -290,7 +285,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec() const bool printInconclusive = (mSettings->certainty.isEnabled(Certainty::inconclusive)); for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) { - if (isUnevaluatedOperator(tok)) { + if (isUnevaluated(tok)) { tok = tok->next()->link(); continue; } @@ -349,7 +344,7 @@ void CheckNullPointer::nullConstantDereference() tok = scope->function->token; // Check initialization list for (; tok != scope->bodyEnd; tok = tok->next()) { - if (isUnevaluatedOperator(tok)) + if (isUnevaluated(tok)) tok = tok->next()->link(); else if (Token::simpleMatch(tok, "* 0")) { diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 239f1ad8d..623c30596 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -607,7 +607,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var } // skip sizeof / offsetof - if (isSizeOfEtc(tok)) + if (isUnevaluated(tok)) tok = tok->linkAt(1); // for/while.. @@ -724,7 +724,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var return true; } - if (isSizeOfEtc(tok)) + if (isUnevaluated(tok)) tok = tok->linkAt(1); else if (tok->str() == "?") { @@ -838,7 +838,7 @@ const Token* CheckUninitVar::checkExpr(const Token* tok, const Variable& var, co { if (!tok) return nullptr; - if (isSizeOfEtc(tok->previous())) + if (isUnevaluated(tok->previous())) return nullptr; if (tok->astOperand1()) { @@ -891,7 +891,7 @@ bool CheckUninitVar::checkIfForWhileHead(const Token *startparentheses, const Va return true; } // skip sizeof / offsetof - if (isSizeOfEtc(tok)) + if (isUnevaluated(tok)) tok = tok->linkAt(1); if ((!isuninit || !membervar.empty()) && tok->str() == "&&") suppressErrors = true; @@ -909,7 +909,7 @@ const Token* CheckUninitVar::checkLoopBodyRecursive(const Token *start, const Va const Token *const end = start->link(); for (const Token *tok = start->next(); tok != end; tok = tok->next()) { // skip sizeof / offsetof - if (isSizeOfEtc(tok)) { + if (isUnevaluated(tok)) { tok = tok->linkAt(1); continue; } @@ -1031,7 +1031,7 @@ const Token* CheckUninitVar::checkLoopBodyRecursive(const Token *start, const Va varIsUsedInRhs = true; return ChildrenToVisit::done; } - if (isSizeOfEtc(t->previous())) + if (isUnevaluated(t->previous())) return ChildrenToVisit::none; return ChildrenToVisit::op1_and_op2; }); @@ -1096,7 +1096,7 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, Alloc alloc if (err) uninitvarError(tok, var.nameToken()->str(), alloc); break; - } else if (isSizeOfEtc(tok)) + } else if (isUnevaluated(tok)) tok = tok->linkAt(1); } @@ -1599,7 +1599,7 @@ void CheckUninitVar::valueFlowUninit() // check every executable scope for (const Scope* scope : symbolDatabase->functionScopes) { for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) { - if (isSizeOfEtc(tok)) { + if (isUnevaluated(tok)) { tok = tok->linkAt(1); continue; } diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index fea0526eb..6a2860886 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -143,7 +143,7 @@ struct ForwardTraversal { // Traverse the parameters of the function before escaping traverseRecursive(tok->next()->astOperand2(), f, traverseUnknown); return Break(Analyzer::Terminate::Escape); - } else if (isUnevaluated(tok)) { + } else if (isUnevaluated(tok->previous())) { if (out) *out = tok->link(); return Progress::Skip; @@ -825,10 +825,6 @@ struct ForwardTraversal { return Progress::Continue; } - static bool isUnevaluated(const Token* tok) { - return Token::Match(tok->previous(), "sizeof|decltype ("); - } - static bool isFunctionCall(const Token* tok) { if (!Token::simpleMatch(tok, "(")) @@ -839,7 +835,7 @@ struct ForwardTraversal { return false; if (Token::simpleMatch(tok->link(), ") {")) return false; - if (isUnevaluated(tok)) + if (isUnevaluated(tok->previous())) return false; return Token::Match(tok->previous(), "%name%|)|]|>"); } diff --git a/lib/reverseanalyzer.cpp b/lib/reverseanalyzer.cpp index a243cc7ea..68d1d55bc 100644 --- a/lib/reverseanalyzer.cpp +++ b/lib/reverseanalyzer.cpp @@ -378,7 +378,7 @@ struct ReverseTraversal { static Token* isUnevaluated(Token* tok) { if (Token::Match(tok, ")|>") && tok->link()) { Token* start = tok->link(); - if (Token::Match(start->previous(), "sizeof|decltype (")) + if (::isUnevaluated(start->previous())) return start->previous(); if (Token::simpleMatch(start, "<")) return start;