This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Dealing with compilers that pretend to be GCC
- From: ludovic dot courtes at inria dot fr (Ludovic Courtès)
- To: Chris Lattner <clattner at apple dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 02 Feb 2012 10:58:35 +0100
- Subject: Re: Dealing with compilers that pretend to be GCC
- References: <87hazrzs5r.fsf@inria.fr> <4F182987.7000302@free.fr> <87y5t3wybv.fsf@inria.fr> <4F182F8E.7090907@free.fr> <20120120013812.GV6710@xvii.vinc17.org> <87r4yuggp5.fsf@inria.fr> <CAH6eHdRHsO1jWNMDwD+Cve_DJ3obUsos7Zd4dVsFGMKVrwfvew@mail.gmail.com> <20120121003228.GA8458@xvii.vinc17.org> <CAH6eHdSqsJJ3avK14+FPFRKR2RTFvyAtp6idNkhp1qhpyskhOg@mail.gmail.com> <799C9B12-FD77-4A40-BDD6-212B4C560F90@apple.com> <87zkd5w5ee.fsf@inria.fr> <F11409AA-8BF2-4A8F-A942-FA17C261A75A@apple.com> <87sjiwoxlv.fsf@inria.fr> <alpine.DEB.2.02.1201311353240.2407@laptop-mg.saclay.inria.fr> <87zkd4ko7b.fsf@inria.fr> <DBA45C7C-E815-4E1A-B165-31D6C5FA3772@apple.com>
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â.