XCode iOS 运算符新的自定义实现

发布于 2024-12-21 20:20:18 字数 420 浏览 1 评论 0原文

XCode 对我的全局运算符 new 的实现发出警告:

void *operator new(size_t blocksize);

它说:'operator new' 缺少异常规范 'throw(std::bad_alloc)'

但我的实现并不打算抛出任何异常,我宁愿将其声明为

void *operator new(size_t blocksize) throw();

然而,后一个实现会导致错误:

声明中的异常规范与先前的声明不匹配

所以,问题是:我真的被迫(为了让 XCode 编译器平静下来)声明一个自定义的“operator new” ' 作为throw(std::bad_alloc) 即使它不会抛出任何异常?

XCode issues warning for my implementation of global operator new:

void *operator new(size_t blocksize);

It says: 'operator new' is missing exception specification 'throw(std::bad_alloc)'

But my implementation does not intend to throw any exception, and I'd rather declare it as

void *operator new(size_t blocksize) throw();

However, the latter implementation leads to an error:

Exception specification in declaration does not match previous declaration

So, the question is: am I really forced (to calm down XCode compiler) to declare a custom 'operator new' as throw(std::bad_alloc) even if it wont throw any exception?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅沫记忆 2024-12-28 20:20:18

所以,问题是:我真的被迫(让 XCode 编译器冷静下来)吗?
将自定义“operator new”声明为 throw(std::bad_alloc),即使它
不会抛出任何异常吗?

是的,你这样做:

http://developer.apple.com/library/ mac/#technotes/tn2185/_index.html

为了完全控制和可移植性,如果您替换其中任何签名,则应该替换所有签名。然而,数组形式的默认实现只是转发到非数组形式。如果您只替换四个非数组形式,则期望默认数组形式转发给您的替换。

So, the question is: am I really forced (to calm down XCode compiler)
to declare a custom 'operator new' as throw(std::bad_alloc) even if it
wont throw any exception?

Yes you do:

http://developer.apple.com/library/mac/#technotes/tn2185/_index.html

For complete control and portability, if you replace any of these signatures, you should replace all of them. However the default implementation of the array forms simply forward to the non-array forms. If you only replace the four non-array forms, expect the default array forms to forward to your replacements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文