We are unsure whether this is actually a false positive or not. Our reasoning is as follows:
The lifetime for pTimer (the raw pointer to the object managed by upTimer) is indeed longer than for upTimer (which gets destroyed when createController ends and this indeed could be a problem), but before that destruction happens, upTimer is already moved into the object managed by upController which has a larger lifetime than pTimer. Had that std::move not happened, then I agree that this is a real error. But isn't this a false positive knowing that the std::move happened?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My colleagues and me are discussing a cppcheck error for some code for which I created the following trimmed down example:
The cppcheck error that we get (using cppcheck 2.16.0) is:
We are unsure whether this is actually a false positive or not. Our reasoning is as follows:
The lifetime for
pTimer
(the raw pointer to the object managed byupTimer
) is indeed longer than forupTimer
(which gets destroyed whencreateController
ends and this indeed could be a problem), but before that destruction happens,upTimer
is already moved into the object managed byupController
which has a larger lifetime thanpTimer
. Had thatstd::move
not happened, then I agree that this is a real error. But isn't this a false positive knowing that thestd::move
happened?Looks like a variation of this issue: https://trac.cppcheck.net/ticket/12794