Skip to content

Commit 9dd0555

Browse files
authored
checkcondition.cpp: fixed -Wbitwise-instead-of-logical Clang warnings (#7736)
these are shown with a make build using Clang
1 parent 876d4ef commit 9dd0555

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

cmake/compileroptions.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
120120
add_compile_options_safe(-Wno-switch-enum)
121121
add_compile_options_safe(-Wno-date-time)
122122
add_compile_options(-Wno-disabled-macro-expansion)
123-
add_compile_options_safe(-Wno-bitwise-instead-of-logical)
124123
add_compile_options(-Wno-sign-compare)
125124
add_compile_options_safe(-Wno-ms-bitfield-padding) # TODO: fix this
126125

lib/checkcondition.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ bool CheckCondition::diag(const Token* tok, bool insert)
7878
return true;
7979
}
8080

81+
bool CheckCondition::diag(const Token* tok1, const Token* tok2)
82+
{
83+
const bool b1 = diag(tok1);
84+
const bool b2 = diag(tok2);
85+
return b1 && b2;
86+
}
87+
8188
bool CheckCondition::isAliased(const std::set<int> &vars) const
8289
{
8390
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
@@ -515,7 +522,7 @@ void CheckCondition::duplicateCondition()
515522

516523
void CheckCondition::duplicateConditionError(const Token *tok1, const Token *tok2, ErrorPath errorPath)
517524
{
518-
if (diag(tok1) & diag(tok2))
525+
if (diag(tok1, tok2))
519526
return;
520527
errorPath.emplace_back(tok1, "First condition");
521528
errorPath.emplace_back(tok2, "Second condition");
@@ -581,7 +588,7 @@ void CheckCondition::overlappingElseIfConditionError(const Token *tok, nonneg in
581588

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

858865
void CheckCondition::oppositeInnerConditionError(const Token *tok1, const Token* tok2, ErrorPath errorPath)
859866
{
860-
if (diag(tok1) & diag(tok2))
867+
if (diag(tok1, tok2))
861868
return;
862869
const std::string s1(tok1 ? tok1->expressionString() : "x");
863870
const std::string s2(tok2 ? tok2->expressionString() : "!x");
@@ -872,7 +879,7 @@ void CheckCondition::oppositeInnerConditionError(const Token *tok1, const Token*
872879

873880
void CheckCondition::identicalInnerConditionError(const Token *tok1, const Token* tok2, ErrorPath errorPath)
874881
{
875-
if (diag(tok1) & diag(tok2))
882+
if (diag(tok1, tok2))
876883
return;
877884
const std::string s1(tok1 ? tok1->expressionString() : "x");
878885
const std::string s2(tok2 ? tok2->expressionString() : "x");
@@ -887,7 +894,7 @@ void CheckCondition::identicalInnerConditionError(const Token *tok1, const Token
887894

888895
void CheckCondition::identicalConditionAfterEarlyExitError(const Token *cond1, const Token* cond2, ErrorPath errorPath)
889896
{
890-
if (diag(cond1) & diag(cond2))
897+
if (diag(cond1, cond2))
891898
return;
892899

893900
const bool isReturnValue = cond2 && Token::simpleMatch(cond2->astParent(), "return");

lib/checkcondition.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ class CPPCHECKLIB CheckCondition : public Check {
115115
// The conditions that have been diagnosed
116116
std::set<const Token*> mCondDiags;
117117
bool diag(const Token* tok, bool insert=true);
118+
/** @brief Mark both token as diagnosed */
119+
bool diag(const Token* tok1, const Token* tok2);
118120
bool isAliased(const std::set<int> &vars) const;
119121
bool isOverlappingCond(const Token * cond1, const Token * cond2, bool pure) const;
120122
void assignIfError(const Token *tok1, const Token *tok2, const std::string &condition, bool result);

0 commit comments

Comments
 (0)