[cfe-dev] Preprocessor operators for #error and #warning

Kyle Sluder kyle at ksluder.com
Fri Apr 11 15:16:59 PDT 2014


Hello,

I'd really like to generate #error and #warning tokens from macros. How
interested would the clang team be in accepting an extension that made
_Error() and _Warning() operators available, similar to C99's _Pragma()
operator?

One preferable difference from _Pragma would be for _Error() and
_Warning() to accept implicit string concatenation. So, for example,
`#define fail(msg) _Error("failed: " msg)` should work—even though it
doesn't work with _Pragma.

Ideally, I'd be able to use printf()-style formatting, since that's what
my macro gets converted to for debug builds. (I want them to convert to
compile-time errors in release builds, to prevent shipping code that
contains that code branch.) But I can understand not wanting to do
string formatting within the compiler.

--Kyle Sluder




More information about the cfe-dev mailing list