问题描述
我正在尝试替换 Visual Studio 和 C++ 中的全局 new 运算符。这是我的代码(为简单起见,仅显示了一个新运算符):
void* operator new(size_t _Size)
{
// Do something
}
它工作正常,但是 Visual Studio 在为我的项目运行代码分析时给我一个警告:
warning C28251: Inconsistent annotation for 'new': this instance has no annotations. The first user-provided annotation on this built-in function is at line vcruntime_new.h(48).
按照 IntelliSense 警告中的建议,使用 vcruntime_new.h 中的注释替换我的 operator new
可以解决警告:
_NODISCARD _Ret_notnull_ _Post_writable_byte_size_(_Size) _VCRT_ALLOCATOR
void* __cdecl operator new(size_t _Size)
{
// Do something
}
- 将 vcruntime_new.h 中的注释用于我自己的替换代码(如上所示)是否安全?
- 这种变化的后果是什么?
- 是否有特殊用例因为注释而不能像以前一样使用“新运算符”?
- 为什么需要进行这种更改?
编辑:
- 我是否正确,注释不会更改生成的二进制文件中的任何内容,并且仅用于静态代码分析? (除了
__cdecl
,它改变了汇编程序,但我猜它应该是标准的?)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)