Dealing with compilers that pretend to be GCC
Ludovic Courtès
ludovic.courtes@inria.fr
Thu Feb 2 09:58:00 GMT 2012
Hi,
Chris Lattner <clattner@apple.com> skribis:
> On Jan 31, 2012, at 5:15 AM, Ludovic Courtès wrote:
>
>>>
>>> Interestingly enough:
>>> $ cat q.c
>>> __has_builtin
>>> $ clang -E q.c
>>> <segfault>
>>
>> Yes, that’s what I was asking.
>>
>> It makes me think that the old CPP predicates (info "(gcc) Obsolete
>> Features") would be more appropriate than compiler magic, with the
>> caveat that they’re presumably not widely supported.
>
> They are similar in spirit. The major difference between the two is that it is easy for __has_feature and friends gracefully degrade when a compiler doesn't support them, because you can do:
>
> #ifndef __has_builtin
> #define __has_builtin(x) 0
> #endif
>
> in your code, but you can't do anything like this for #assertion. That and assertions don't have any coverage over the features that you're interested in, and the grammar doesn't have a good way to handle multiple cases like features/attributes/extensions/etc.
Rather than assertions, one could use predicates:
#if #has_builtin(foo) && #has_attribute(bar)
...
#endif
The difference being that (1) predicates were designed specifically for
this purpose, and (2) there’s no magic involved.
Thanks,
Ludo’.
More information about the Gcc
mailing list