Skip to content

Commit 7c7ed58

Browse files
Fix #12320 FP knownConditionTrueFalse with if chain (#8547)
1 parent 18f1808 commit 7c7ed58

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/programmemory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct ExprIdToken {
102102
};
103103

104104
struct CPPCHECKLIB ProgramMemory {
105-
using Map = std::unordered_map<ExprIdToken, ValueFlow::Value, ExprIdToken::Hash>;
105+
using Map = std::map<ExprIdToken, ValueFlow::Value>;
106106

107107
ProgramMemory() : mValues(new Map()) {}
108108

test/testcondition.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5174,6 +5174,15 @@ class TestCondition : public TestFixture {
51745174
TODO_ASSERT_EQUALS("",
51755175
"[test.cpp:11:14]: (style) Condition 'p->i==o' is always true [knownConditionTrueFalse]\n",
51765176
errout_str());
5177+
5178+
check("void f(int x) {\n" // #12320
5179+
" int a = 0, b = 0, c = 0;\n"
5180+
" a = x;\n"
5181+
" if (a) b = x;\n"
5182+
" if (b) c = x;\n"
5183+
" if (c) {}\n"
5184+
"}\n");
5185+
ASSERT_EQUALS("", errout_str());
51775186
}
51785187

51795188
void alwaysTrueInfer() {

0 commit comments

Comments
 (0)