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

Richard Smith richard at metafoo.co.uk
Sun Apr 13 13:29:19 PDT 2014


On Sun, Apr 13, 2014 at 12:38 PM, Kyle Sluder <kyle at ksluder.com> wrote:

> On Apr 12, 2014, at 2:34 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk>
> wrote:
> >
> > For _Error, you can use C11's _Static_assert():
> >
> > #define fail(msg) _Static_assert(0, msg)
> >
> > There's no standard equivalent for #warning, unfortunately.
>
> That workaround is sufficient for my use case, but the output is noisy and
> as you note it doesn't work for those who treat warning differently from
> errors.
>
> So, can anyone opine on whether such a patch would be accepted?


I don't think we want _Warning and _Error. You can use #pragma message to
emit a warning (as _Pragma("message \"...\"") within your macro). I'd much
prefer to add support for something like '#pragma clang error "blah"'
rather than adding something like _Error(...), if _Static_assert is somehow
insufficient, but I'd like to understand what's wrong with _Static_assert
first.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140413/8c98b030/attachment.html>


More information about the cfe-dev mailing list