【问题标题】:Microsoft VS2015 C++ Core Guidelines Analysis: "no array to pointer decay (bounds.3)" for vtable?Microsoft VS2015 C++ 核心指南分析:vtable 的“没有指向指针衰减的数组(bounds.3)”?
【发布时间】:2018-08-14 13:55:35
【问题描述】:

当我在我的 VS2015 项目上运行 CppCoreCheck 代码分析时,我收到了许多似乎“无法修复”的警告,因为它们涉及类和 vtable 的底层 C++ 实现:

一个示例类:

// Header file
class IMyClass {
public:
    virtual ~IMyClass() {}
    virtual void MyMethod() = 0;
};

class MyClass : public virtual IMyClass {
public:
    MyClass();
    virtual ~MyClass();
    virtual void MyMethod() override;
};


// Impl file
MyClass::MyClass() { } // This line creates two warnings from CppCoreCheck
MyClass::~MyClass() { }
void MyClass::MyMethod() { }

还有警告:

warning C26485: Expression 'MyClass::`vbtable'': No array to pointer decay. (bounds.3: http://go.microsoft.com/fwlink/p/?LinkID=620415)
warning C26481: Don't use pointer arithmetic. Use span instead. (bounds.1: http://go.microsoft.com/fwlink/p/?LinkID=620413)

警告所抱怨的行引用了 MyClass 的构造函数定义

为了清楚起见;我没有在代码中的任何地方直接引用 vtable;我只是以 100% 的典型方式使用虚拟继承。

有人可以确认这是否是特定于 VS2015 的 CppCoreCheck 实现的错误吗?如果是这样,在VS2017中解决了吗?

【问题讨论】:

  • 你能提供一个发生这种情况的小代码示例吗?
  • 当然;道歉。我已经用完整的代码 sn-p 更新了问题。
  • 参见:developercommunity.visualstudio.com/content/problem/60755/…"...修复于:visual studio 2017 版本 15.5..."
  • 将你的代码粘贴到VS2017,我没有收到警告信息。
  • 太糟糕了,它无法在 CppCoreChecker NuGet 包中解决。我的公司还没有更新到 VS2017,但我们现在会忍受额外的警告。随意添加这个作为答案。

标签: c++ visual-studio-2015 cpp-core-guidelines


【解决方案1】:

这是 VS2015 中的一个已知问题,不会修复。是resolved as of VS2017, v15.5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-05
    • 2020-10-02
    • 2011-11-14
    • 2011-01-03
    • 2022-01-10
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多