Skip to content

Commit 79ca30a

Browse files
Partial fix for #10452 FN knownConditionTrueFalse with bool and float (danmar#8438)
The bailout was added in danmar@bc3f555 but seems unrelated to that change. Also, we would still warn for e.g. `!b()` or `b() == false`. --------- Co-authored-by: chrchr-github <noreply@github.com>
1 parent 4f8a48d commit 79ca30a

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

gui/statsdialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void StatsDialog::setProject(const ProjectFile* projectFile)
113113
if (!statsFile.isEmpty()) {
114114
QChartView *chartView = createChart(statsFile, "cppcheck");
115115
mUI->mTabHistory->layout()->addWidget(chartView);
116+
// cppcheck-suppress knownConditionTrueFalse - TODO in getClangAnalyzer()
116117
if (projectFile->getClangAnalyzer()) {
117118
chartView = createChart(statsFile, CLANG_ANALYZER);
118119
mUI->mTabHistory->layout()->addWidget(chartView);

lib/checkcondition.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,11 +1524,6 @@ void CheckCondition::alwaysTrueFalse()
15241524
}
15251525
if (!tok->hasKnownIntValue())
15261526
continue;
1527-
if (Token::Match(tok->previous(), "%name% (") && tok->previous()->function()) {
1528-
const Function* f = tok->previous()->function();
1529-
if (f->functionScope && Token::Match(f->functionScope->bodyStart, "{ return true|false ;"))
1530-
continue;
1531-
}
15321527
const Token* condition = nullptr;
15331528
{
15341529
// is this a condition..

test/testcondition.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4852,6 +4852,15 @@ class TestCondition : public TestFixture {
48524852
"}\n");
48534853
ASSERT_EQUALS("[test.cpp:6:9] -> [test.cpp:9:9]: (warning) Identical condition 'a', second condition is always false [identicalConditionAfterEarlyExit]\n",
48544854
errout_str());
4855+
4856+
check("bool b() { return false; }\n" // #10452
4857+
"void f() {\n"
4858+
" if (b()) {}\n"
4859+
" if (!b()) {}\n"
4860+
"}\n");
4861+
ASSERT_EQUALS("[test.cpp:3:10]: (style) Condition 'b()' is always false [knownConditionTrueFalse]\n"
4862+
"[test.cpp:4:9]: (style) Condition '!b()' is always true [knownConditionTrueFalse]\n",
4863+
errout_str());
48554864
}
48564865

48574866
void alwaysTrueSymbolic()

0 commit comments

Comments
 (0)