You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 17:52:32