[cfe-dev] magic __has_feature macro
Chris Lattner
clattner at apple.com
Fri Jun 12 22:44:18 PDT 2009
On Jun 12, 2009, at 6:18 PM, Eli Friedman wrote:
> On Fri, Jun 12, 2009 at 6:03 PM, Chris Lattner<clattner at apple.com>
> wrote:
>> Hi All,
>>
>> As Clang "grows up", it will continue to get more features. I'd like
>> to add new "__has_feature" builtin function-like macro that evaluates
>> to 0 or 1 if clang has a specified feature.
>
> What does it evaluate to if clang doesn't have the specified
> feature? :)
haha. :)
> Sounds like a good idea.
Ok, my proposed use of if defined won't work because of the parsing
structure of pp conditionals. However, something like this will work:
#ifndef __has_feature
#define __has_feature(x) 0
#endif
// ...
#if __has_feature(x)
... whatever ...
#endif
I also plan to add a __has_builtin(x) as well, so that we can write
things like:
#if __has_builtin(__builtin_trap)
__builtin_trap();
#else
abort();
#endif
Look, no autoconf, and no fragile compiler version checks! :)
I'll start working on this.
-Chris
More information about the cfe-dev
mailing list