With Cppcheck I get:
Unused private function: 'Derived::Func'.
Is this a false positive?
#include <cstdint>
class Interface {
public:
Interface() = default;
virtual ~Interface() = default;
Interface(const Interface &other) = delete;
Interface(Interface &&other) = delete;
auto operator=(const Interface &other) -> Interface & = delete;
auto operator=(Interface &&other) -> Interface & = delete;
virtual auto IFunc() -> void = 0;
};
class Derived final : public Interface {
public:
auto IFunc() -> void override;
private:
auto Func() -> void;
std::uint16_t mMember{};
};
auto Derived::IFunc() -> void {
Func();
return;
}
auto Derived::Func() -> void {
mMember = 42;
return;
}
Derived::Func() should not be marked as unused because it is clearly used in Derived::IFunc().
Is this a false positive?
Yes, it is, clearly. As you have stated, Derived::Func is used in Derived::IFunc.
Strangely, the warning disappears if you change the declaration (but not necessarily also the definition) of Derived::IFunc from using auto and the trailing return type specifier (-> void) to the 'old-fashioned', void IFunc() override;. At least, that fixes it in the online demo.
The warning also goes away if you just remove the definitions (out-of-class bodies) of IFunc and Func.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With