Cppcheck提示“未使用私有函数”是否为误报?
这是Cppcheck的误报吗?
是的,这属于Cppcheck的误报。
你的代码中,Derived类被标记为final,它重写了基类Interface的纯虚函数IFunc,并且在IFunc的实现里明确调用了私有成员函数Func,Func还修改了成员变量mMember,完全符合“已被使用”的判定标准。
出现这个误报的原因大概率是Cppcheck在分析虚函数与私有成员函数的调用关系时,没有正确追踪到final类中重写虚函数对私有函数的调用逻辑。
附上你的代码:
#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; }
内容的提问来源于stack exchange,提问作者mbox
相关产品推荐
相关产品推荐

