当我在我的 VS2015 项目上运行 CppCoreCheck 代码分析时,我收到许多看起来“无法修复”的警告,因为它们指的是类和 vtables 的底层 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 中解决了?
最佳答案
这是 VS2015 中的一个已知问题,不会被修复。是resolved as of VS2017, v15.5 .
关于c++ - Microsoft VS2015 C++ Core Guidelines分析: "no array to pointer decay (bounds.3)" for vtable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51843205/