Opened 5 years ago

Closed 4 years ago

#10618 closed defect (fixed)

FP knownConditionTrueFalse with virtual function

Reported by: chrchr Owned by: noone
Priority: Normal Milestone: 2.9
Component: False positive Version:
Keywords: knownConditionTrueFalse exprDependsOnThis Cc:

Description (last modified by amai)

Line 
1class B {
2public:
3 void Modify();
4 virtual void CalledByModify();
5};
6
7class D : public B
8{
9public:
10 int i{};
11 void test();
12 void CalledByModify() override { i = 0; }
13};
14
15void D::test()
16{
17 i = 1;
18 B::Modify();
19 if (i == 1)
20 {
21 }
22}

Output:

bar.cpp:29:8: style: Condition 'i==1' is always true [knownConditionTrueFalse]
 if (i == 1)
       ^
bar.cpp:27:6: note: Assignment 'i=1', assigned value is 1
 i = 1;
     ^
bar.cpp:29:8: note: Condition 'i==1' is always true
 if (i == 1)
       ^

Tested with https://github.com/danmar/cppcheck/commit/6a822f4c06994e4a6ddeb2d9434201e645d53654.

Change History (4)

comment:1 by pfultz2, 5 years ago

Keywords: exprDependsOnThis added; virtual removed

The exprDependsOnThis function needs to be updated to better detect functions from the base class.

comment:2 by amai, 5 years ago

Description: modified (diff)

comment:3 by amai, 5 years ago

Description: modified (diff)

comment:4 by chrchr, 4 years ago

Milestone: 2.9
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.