RawPtr = tmp.get() captures the address of the heap object owned by the local tmp. On the very next line, std::move(tmp) transfers that ownership into Consumer::Owned, which is stored inside ConsumerInstance, a member with a lifetime far longer than the local tmp variable.
10) functionStatic doesn't detect that a member function requires an instance when its only "member use" is an unqualified call to a non-static sibling overload
cppcheck reports that the second Notify overload "can be static". The unqualified call Notify(id, value) is equivalent to this->Notify(id, value) and resolves via overload resolution to the non-static overload that mutates Sink. Since it needs this it can't be static.
Expected: No functionStatic warning, since the function needs an object instance from the call to the non-static overload.
Last edit: Long Huang 2026-08-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
expected result: no errors
actual result: error: Returning pointer to local variable 'tmp' that will be invalid when returning. [returnDanglingLifetime]
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
10) functionStatic doesn't detect that a member function requires an instance when its only "member use" is an unqualified call to a non-static sibling overload
The provided example does not compile.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
9) danglingLifetime doesn't account for ownership being transferred to a longer-lived owner via std::move immediately after capturing a raw pointer
Minimal reproduction:
RawPtr = tmp.get() captures the address of the heap object owned by the local
tmp. On the very next line, std::move(tmp) transfers that ownership into Consumer::Owned, which is stored inside ConsumerInstance, a member with a lifetime far longer than the local tmp variable.10) functionStatic doesn't detect that a member function requires an instance when its only "member use" is an unqualified call to a non-static sibling overload
Minimal reproduction:
cppcheck reports that the second Notify overload "can be static". The unqualified call Notify(id, value) is equivalent to this->Notify(id, value) and resolves via overload resolution to the non-static overload that mutates Sink. Since it needs
thisit can't be static.Expected: No functionStatic warning, since the function needs an object instance from the call to the non-static overload.
Last edit: Long Huang 2026-08-04
Hah I was just trying to make a minimal example for the dangling lifetime issue. Here is what I have right now:
expected result: no errors
actual result: error: Returning pointer to local variable 'tmp' that will be invalid when returning. [returnDanglingLifetime]
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14958
Thank you, there're a few more in the initial and 2nd posts that are still awaiting sourceforge moderator approval in this thread.
The provided example does not compile.