FP knownConditionTrueFalse with virtual function
| Line | |
|---|
| 1 | class B {
|
|---|
| 2 | public:
|
|---|
| 3 | void Modify();
|
|---|
| 4 | virtual void CalledByModify();
|
|---|
| 5 | };
|
|---|
| 6 |
|
|---|
| 7 | class D : public B
|
|---|
| 8 | {
|
|---|
| 9 | public:
|
|---|
| 10 | int i{};
|
|---|
| 11 | void test();
|
|---|
| 12 | void CalledByModify() override { i = 0; }
|
|---|
| 13 | };
|
|---|
| 14 |
|
|---|
| 15 | void 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)
| Keywords: |
exprDependsOnThis added; virtual removed
|
| Description: |
modified (diff)
|
| Description: |
modified (diff)
|
| Milestone: |
→ 2.9
|
| Resolution: |
→ fixed
|
| Status: |
new → closed
|
The
exprDependsOnThisfunction needs to be updated to better detect functions from the base class.