Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 886
Clinton Avatar asked May 24 '11 08:05

Clinton


2 Answers

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.

like image 152
Lightness Races in Orbit Avatar answered Nov 07 '22 10:11

Lightness Races in Orbit


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.

like image 3
vines Avatar answered Nov 07 '22 11:11

vines