Skip to content

Commit 8c0561a

Browse files
Add tests for #6870, #10749 (#4089)
1 parent c710335 commit 8c0561a

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

test/testcondition.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,6 +4098,35 @@ class TestCondition : public TestFixture {
40984098
// #8358
40994099
check("void f(double d) { if ((d * 0) != 0) {} }");
41004100
ASSERT_EQUALS("", errout.str());
4101+
4102+
// #6870
4103+
check("struct S {\n"
4104+
" int* p;\n"
4105+
" void f() const;\n"
4106+
" int g();\n"
4107+
"};\n"
4108+
"void S::f() {\n"
4109+
" if ((p == NULL) || ((p) && (g() >= *p))) {}\n"
4110+
"}\n");
4111+
ASSERT_EQUALS("[test.cpp:7]: (style) Condition 'p' is always true\n", errout.str());
4112+
4113+
// #10749
4114+
check("struct Interface {\n"
4115+
" virtual int method() = 0;\n"
4116+
"};\n"
4117+
"struct Child : Interface {\n"
4118+
" int method() override { return 0; }\n"
4119+
" auto foo() {\n"
4120+
" if (method() == 0)\n"
4121+
" return true;\n"
4122+
" else\n"
4123+
" return false;\n"
4124+
" }\n"
4125+
"};\n"
4126+
"struct GrandChild : Child {\n"
4127+
" int method() override { return 1; }\n"
4128+
"};\n");
4129+
ASSERT_EQUALS("", errout.str());
41014130
}
41024131

41034132
void alwaysTrueSymbolic()

0 commit comments

Comments
 (0)