【问题标题】:How to make cppcheck 2.5 show error on calls to a virtual function in constructor. Older version shows this error如何使 cppcheck 2.5 在构造函数中调用虚函数时显示错误。旧版本显示此错误
【发布时间】:2021-09-17 08:30:48
【问题描述】:

在cppcheck规则列表中有

我已经在我的解决方案中的几个类中编写了一个对虚函数的调用,并对它们运行 cppcheck,但它没有显示此错误。

我使用过 GUI,还使用 ​​--enable=style 和 --enable=all 从命令行运行 cppcheck

如何让 cppcheck 显示这个问题? 我正在使用最新的 cppcheck

另一个我运行 cppcheck 的虚拟代码

class A
{
public:
    A() { }
    virtual void fin() = 0;
};

class B : public A
{
public:
    B() { fin(); }
    void fin() { std::cout << "l"; }
};

class C : public B
{
public:
    C() {}
    void fin() { std::cout << "c"; }
};

更新:我检查了 cppcheck 1.8,它显示了这个错误。尽管 2.5 的规则集规定它应该找到这样的规则,但 2.5 没有显示它们发生了什么?

【问题讨论】:

标签: c++ c++11 static-analysis cppcheck


【解决方案1】:

我发现这条评论https://sourceforge.net/p/cppcheck/discussion/general/thread/b18f7aaf/#d726

它将在下一个版本中修复。现在我已经禁用了 查看。但是,如果我们正确编写此类警告,它可以再次启用。 检查器必须确保该类是基类!

帖子涉及 1.84

查看仍然禁用的代码: https://github.com/danmar/cppcheck/blob/6397e29f84de53655904326ef1ca892a509275c5/lib/checkclass.h

// FIXME: Only report warnings for inherited classes
// checkClass.checkVirtualFunctionCallInConstructor();

【讨论】:

  • 谢谢!我是 Cppcheck 开发人员,我会看看..
  • 我已经修复了 FIXME。这将在 Cppcheck-2.6 中修复。
猜你喜欢
  • 1970-01-01
  • 2021-11-28
  • 1970-01-01
  • 2014-02-15
  • 2018-05-16
  • 1970-01-01
  • 1970-01-01
  • 2021-07-18
  • 2014-01-03
相关资源
最近更新 更多