Skip to content

Commit 91941c2

Browse files
Fix #15065 FN knownConditionTrueFalse (array of std::string) (cppcheck-opensource#8897)
1 parent 71437f2 commit 91941c2

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎lib/valueflow.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static void valueFlowArrayBool(TokenList& tokenlist, const Settings& settings)
727727
}
728728
if (!var)
729729
continue;
730-
if (!var->isArray() || var->isArgument() || var->isStlType())
730+
if (!var->isArray() || var->isArgument() || var->getTypeName() == "std::array")
731731
continue;
732732
if (isNonZero(getOtherOperand(tok)) && Token::Match(tok->astParent(), "%comp%"))
733733
continue;
@@ -1169,7 +1169,7 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett
11691169
value.setImpossible();
11701170
setTokenValue(tok, std::move(value), settings);
11711171
} else if (tok->variable() && tok->variable()->isArray() && !tok->variable()->isArgument() &&
1172-
!tok->variable()->isStlType()) {
1172+
tok->variable()->getTypeName() != "std::array") {
11731173
ValueFlow::Value value{0};
11741174
value.setImpossible();
11751175
setTokenValue(tok, std::move(value), settings);

‎test/testcondition.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3449,6 +3449,12 @@ class TestCondition : public TestFixture {
34493449
"}\n");
34503450
ASSERT_EQUALS("", errout_str());
34513451

3452+
check("std::string a[3];\n" // #15065
3453+
"void f() {\n"
3454+
" if (a) {}\n"
3455+
"}\n");
3456+
ASSERT_EQUALS("[test.cpp:3:8]: (style) Condition 'a' is always true [knownConditionTrueFalse]\n", errout_str());
3457+
34523458
// Avoid FP when condition comes from macro
34533459
check("#define NOT !\n"
34543460
"void f() {\n"

0 commit comments

Comments
 (0)