Fix issue 9277: FP: Dont warn for knwon conditions in if constexpr (#2085)
This commit is contained in:
parent
3aef0c9bd3
commit
3e0d1141d3
|
@ -1345,7 +1345,7 @@ void CheckCondition::alwaysTrueFalse()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const bool constIfWhileExpression =
|
const bool constIfWhileExpression =
|
||||||
tok->astParent() && Token::Match(tok->astTop()->astOperand1(), "if|while") &&
|
tok->astParent() && Token::Match(tok->astTop()->astOperand1(), "if|while") && !tok->astTop()->astOperand1()->isConstexpr() &&
|
||||||
(Token::Match(tok->astParent(), "%oror%|&&") || Token::Match(tok->astParent()->astOperand1(), "if|while"));
|
(Token::Match(tok->astParent(), "%oror%|&&") || Token::Match(tok->astParent()->astOperand1(), "if|while"));
|
||||||
const bool constValExpr = tok->isNumber() && Token::Match(tok->astParent(),"%oror%|&&|?"); // just one number in boolean expression
|
const bool constValExpr = tok->isNumber() && Token::Match(tok->astParent(),"%oror%|&&|?"); // just one number in boolean expression
|
||||||
const bool compExpr = Token::Match(tok, "%comp%|!"); // a compare expression
|
const bool compExpr = Token::Match(tok, "%comp%|!"); // a compare expression
|
||||||
|
|
|
@ -566,6 +566,13 @@ public:
|
||||||
setFlag(fIncompleteVar, b);
|
setFlag(fIncompleteVar, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isConstexpr() const {
|
||||||
|
return getFlag(fConstexpr);
|
||||||
|
}
|
||||||
|
void isConstexpr(bool b) {
|
||||||
|
setFlag(fConstexpr, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isBitfield() const {
|
bool isBitfield() const {
|
||||||
return mImpl->mBits > 0;
|
return mImpl->mBits > 0;
|
||||||
|
@ -1098,6 +1105,7 @@ private:
|
||||||
fIsAttributeNodiscard = (1 << 23), // __attribute__ ((warn_unused_result)), [[nodiscard]]
|
fIsAttributeNodiscard = (1 << 23), // __attribute__ ((warn_unused_result)), [[nodiscard]]
|
||||||
fAtAddress = (1 << 24), // @ 0x4000
|
fAtAddress = (1 << 24), // @ 0x4000
|
||||||
fIncompleteVar = (1 << 25),
|
fIncompleteVar = (1 << 25),
|
||||||
|
fConstexpr = (1 << 26),
|
||||||
};
|
};
|
||||||
|
|
||||||
Token::Type mTokType;
|
Token::Type mTokType;
|
||||||
|
|
|
@ -4233,6 +4233,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
} else if (tok->strAt(1) == "constexpr") {
|
} else if (tok->strAt(1) == "constexpr") {
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
|
tok->isConstexpr(true);
|
||||||
} else {
|
} else {
|
||||||
syntaxError(tok);
|
syntaxError(tok);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3206,6 +3206,16 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 'array' is always true\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 'array' is always true\n", errout.str());
|
||||||
|
|
||||||
|
// #9277
|
||||||
|
check("int f() {\n"
|
||||||
|
" constexpr bool x = true;\n"
|
||||||
|
" if constexpr (x)\n"
|
||||||
|
" return 0;\n"
|
||||||
|
" else\n"
|
||||||
|
" return 1;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void multiConditionAlwaysTrue() {
|
void multiConditionAlwaysTrue() {
|
||||||
|
|
Loading…
Reference in New Issue