开发者

In C++0x is there something like static_assert which gives a warning instead of an error?

开发者 https://www.devze.com 2023-03-08 04:04 出处:网络
I would like to do this for usages whi开发者_开发知识库ch may be inefficient but not necessarily incorrect.No.

I would like to do this for usages whi开发者_开发知识库ch may be inefficient but not necessarily incorrect.


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消