[cfe-dev] magic __has_feature macro

Chris Lattner clattner at apple.com
Sat Jun 13 18:58:55 PDT 2009


On Jun 12, 2009, at 10:44 PM, Chris Lattner wrote:
>> Sounds like a good idea.
> #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! :)

Ok, I just committed the last patch, please let me know if you notice  
any weirdness.  Documentation here:
http://clang.llvm.org/docs/LanguageExtensions.html#feature_check

Whenever we add new attributes or other stuff, we should add them to  
__has_feature.  Also, it would probably make sense to add  
__has_feature support for various C++'0x sub-features that we already  
support like static_assert.  Please make sure that these are  
documented in the extensions manual when they are added though.

-Chris





More information about the cfe-dev mailing list