Clinton
Clinton

Reputation: 23135

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.

Upvotes: 13

Views: 1127

Answers (3)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385284

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.

Upvotes: 6

vines
vines

Reputation: 5225

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.

Upvotes: 3

Puppy
Puppy

Reputation: 146978

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

Upvotes: 0

Related Questions