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
1 change: 0 additions & 1 deletion cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options_safe(-Wno-switch-enum)
add_compile_options_safe(-Wno-date-time)
add_compile_options(-Wno-disabled-macro-expansion)
add_compile_options_safe(-Wno-bitwise-instead-of-logical)
add_compile_options(-Wno-sign-compare)
add_compile_options_safe(-Wno-ms-bitfield-padding) # TODO: fix this

Expand Down
17 changes: 12 additions & 5 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ bool CheckCondition::diag(const Token* tok, bool insert)
return true;
}

bool CheckCondition::diag(const Token* tok1, const Token* tok2)
{
const bool b1 = diag(tok1);
const bool b2 = diag(tok2);
return b1 && b2;
}

bool CheckCondition::isAliased(const std::set<int> &vars) const
{
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
Expand Down Expand Up @@ -515,7 +522,7 @@ void CheckCondition::duplicateCondition()

void CheckCondition::duplicateConditionError(const Token *tok1, const Token *tok2, ErrorPath errorPath)
{
if (diag(tok1) & diag(tok2))
if (diag(tok1, tok2))
return;
errorPath.emplace_back(tok1, "First condition");
errorPath.emplace_back(tok2, "Second condition");
Expand Down Expand Up @@ -581,7 +588,7 @@ void CheckCondition::overlappingElseIfConditionError(const Token *tok, nonneg in

void CheckCondition::oppositeElseIfConditionError(const Token *ifCond, const Token *elseIfCond, ErrorPath errorPath)
{
if (diag(ifCond) & diag(elseIfCond))
if (diag(ifCond, elseIfCond))
return;
std::ostringstream errmsg;
errmsg << "Expression is always true because 'else if' condition is opposite to previous condition at line "
Expand Down Expand Up @@ -857,7 +864,7 @@ static std::string innerSmtString(const Token * tok)

void CheckCondition::oppositeInnerConditionError(const Token *tok1, const Token* tok2, ErrorPath errorPath)
{
if (diag(tok1) & diag(tok2))
if (diag(tok1, tok2))
return;
const std::string s1(tok1 ? tok1->expressionString() : "x");
const std::string s2(tok2 ? tok2->expressionString() : "!x");
Expand All @@ -872,7 +879,7 @@ void CheckCondition::oppositeInnerConditionError(const Token *tok1, const Token*

void CheckCondition::identicalInnerConditionError(const Token *tok1, const Token* tok2, ErrorPath errorPath)
{
if (diag(tok1) & diag(tok2))
if (diag(tok1, tok2))
return;
const std::string s1(tok1 ? tok1->expressionString() : "x");
const std::string s2(tok2 ? tok2->expressionString() : "x");
Expand All @@ -887,7 +894,7 @@ void CheckCondition::identicalInnerConditionError(const Token *tok1, const Token

void CheckCondition::identicalConditionAfterEarlyExitError(const Token *cond1, const Token* cond2, ErrorPath errorPath)
{
if (diag(cond1) & diag(cond2))
if (diag(cond1, cond2))
return;

const bool isReturnValue = cond2 && Token::simpleMatch(cond2->astParent(), "return");
Expand Down
2 changes: 2 additions & 0 deletions lib/checkcondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class CPPCHECKLIB CheckCondition : public Check {
// The conditions that have been diagnosed
std::set<const Token*> mCondDiags;
bool diag(const Token* tok, bool insert=true);
/** @brief Mark both token as diagnosed */
bool diag(const Token* tok1, const Token* tok2);
bool isAliased(const std::set<int> &vars) const;
bool isOverlappingCond(const Token * cond1, const Token * cond2, bool pure) const;
void assignIfError(const Token *tok1, const Token *tok2, const std::string &condition, bool result);
Expand Down
Loading