在 C++0x 中是否有类似 static_assert 的东西会给出警告而不是错误?

发布于 2024-11-09 05:06:17 字数 32 浏览 8 评论 0原文

我想对可能效率低下但不一定不正确的用法执行此操作。

I would like to do this for usages which may be inefficient but not necessarily incorrect.

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

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

发布评论

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

评论(3

美男兮 2024-11-16 05:06:17

否。

断言失败表示存在阻止程序完成的问题(执行 [运行时断言] 或编译 [静态断言])。

事实上,只要实现发出诊断(包括继续执行),就可以执行任何操作。但实际上,主流工具链的行为几乎都是相同的:它们都会出错。您当然不能将它们破解为用户定义的内容。

No.

An assertion failure indicates a problem preventing the program from being completed (be that execution [run-time assertions], or compilation [static assertions]).

In truth, an implementation is allowed to do anything as long as they emit a diagnostic (including continuing execution). But, in practice, mainstream toolchains will all behave pretty much the same: they will error out. You certainly can't hack them to something user-defined.

千笙结 2024-11-16 05:06:17

为此目的,C++0x 中引入了这些属性。请参阅http://docwiki.embarcadero.com/RADStudio/en/C%2B% 2B0x_attribute_deprecated 为例。

The attributes are introduced in C++0x for that purpose. See http://docwiki.embarcadero.com/RADStudio/en/C%2B%2B0x_attribute_deprecated for an example.

秋心╮凉 2024-11-16 05:06:17

不符合标准,不。您可以在许多编译器中找到#warning,但在大多数情况下这实际上并不相同。

Not as Standard, no. You can find #warning in many compilers, but that's really not the same in most situations.

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