Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,14 @@ class TestOther : public TestFixture {
" 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() {
Expand Down
7 changes: 7 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5473,6 +5473,13 @@ class TestUnusedVar : public TestFixture {
" 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() {
Expand Down