In our code base, we are getting some false positives related to selfAssignment. I have tried to distill it into a minimal example. With version 2.1 and --enable=all, the code below results in
warning: Redundant assignment of '*this' to itself. [selfAssignment]
class Foo { int i = 0; void nonconst() { i = 1;} public: void bar() { Foo old = *this; nonconst(); *this = old;} }; int main() { Foo f; f.bar(); return 0; }
Thanks for reporting! I have created this ticket: https://trac.cppcheck.net/ticket/9785
hmm.. I fail to reproduce this FP with cppcheck-2.0 and cppcheck-2.2 and cppcheck-2.2 ... can you still reproduce the problem?
I just ran 2.1 again and got this:
"c:\Program Files\Cppcheck\cppcheck.exe" --enable=all --inconclusive sa.cpp Checking sa.cpp ... sa.cpp:8:9: warning: Redundant assignment of '*this' to itself. [selfAssignment] *this = old;} ^
Version 2.3 does not report the warning, I guess the problem was fixed sometime in between 2.1 and 2.2?
ok thanks! I close it.
Log in to post a comment.
In our code base, we are getting some false positives related to selfAssignment. I have tried to distill it into a minimal example. With version 2.1 and --enable=all, the code below results in
Thanks for reporting! I have created this ticket: https://trac.cppcheck.net/ticket/9785
hmm.. I fail to reproduce this FP with cppcheck-2.0 and cppcheck-2.2 and cppcheck-2.2 ... can you still reproduce the problem?
I just ran 2.1 again and got this:
Version 2.3 does not report the warning, I guess the problem was fixed sometime in between 2.1 and 2.2?
ok thanks! I close it.