Fix #11315 FP zerodivcond from enum definition / #11310 FP unassignedVariable with static variable (#4476)
* Fix #11315 FP zerodivcond from enum definition * Simplify Boolean expression * Fix #11310 FP unassignedVariable with static variable
This commit is contained in:
parent
3b840e7ff1
commit
cb6f04a16c
|
@ -147,9 +147,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown) const
|
|||
}
|
||||
|
||||
static bool isUnevaluated(const Token* tok) {
|
||||
if (tok && Token::Match(tok->previous(), "sizeof|decltype ("))
|
||||
return true;
|
||||
return false;
|
||||
return tok && Token::Match(tok->previous(), "sizeof|decltype (");
|
||||
}
|
||||
|
||||
bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Settings *settings)
|
||||
|
|
|
@ -1990,6 +1990,8 @@ void CheckOther::checkZeroDivision()
|
|||
continue;
|
||||
if (!tok->valueType() || !tok->valueType()->isIntegral())
|
||||
continue;
|
||||
if (tok->scope() && tok->scope()->type == Scope::eEnum) // don't warn for compile-time error
|
||||
continue;
|
||||
|
||||
// Value flow..
|
||||
const ValueFlow::Value *value = tok->astOperand2()->getValue(0LL);
|
||||
|
|
|
@ -1337,9 +1337,11 @@ void CheckUnusedVar::checkFunctionVariableUsage()
|
|||
}
|
||||
}
|
||||
// variable has not been written but has been modified
|
||||
else if (usage._modified && !usage._write && !usage._allocateMemory && var && !var->isStlType())
|
||||
else if (usage._modified && !usage._write && !usage._allocateMemory && var && !var->isStlType()) {
|
||||
if (var->isStatic()) // static variables are initialized by default
|
||||
continue;
|
||||
unassignedVariableError(usage._var->nameToken(), varname);
|
||||
|
||||
}
|
||||
// variable has been read but not written
|
||||
else if (!usage._write && !usage._allocateMemory && var && !var->isStlType() && !isEmptyType(var->type()))
|
||||
unassignedVariableError(usage._var->nameToken(), varname);
|
||||
|
|
|
@ -794,6 +794,14 @@ private:
|
|||
" return remainder;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #11315
|
||||
checkP("#define STATIC_ASSERT(c) \\\n"
|
||||
"do { enum { sa = 1/(int)(!!(c)) }; } while (0)\n"
|
||||
"void f() {\n"
|
||||
" STATIC_ASSERT(sizeof(int) == sizeof(FOO));\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nanInArithmeticExpression() {
|
||||
|
|
|
@ -5473,6 +5473,13 @@ private:
|
|||
" array[value] = 1;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("int fun() {\n" // #11310
|
||||
" static int k;\n"
|
||||
" k++;\n"
|
||||
" return k;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarextern() {
|
||||
|
|
Loading…
Reference in New Issue