[cfe-users] __builtin_constant_p(), __builtin_expect() and __builtin_types_compatible_p() and __has_builtin()

Chris Hall via cfe-users cfe-users at lists.llvm.org
Fri Aug 9 10:32:40 PDT 2019


On 09/08/2019 15:00, Matthew Fernandez wrote:
>> On Aug 9, 2019, at 05:23, Chris Hall via cfe-users wrote:
>>
>> I find that __builtin_constant_p() works as expected, but 
>> __has_builtin(constant_p) denies it !

> I believe you need __has_builtin(__builtin_constant_p).

Ah :-(  So you do... sorry... I have no idea why I thought otherwise :-(

>> Similarly __builtin_expect() and __builtin_types_compatible_p() !

Except that __has_builtin(__builtin_types_compatible_p) also denies it.

    #include <stdio.h>

    int
    main(int argc, char* argv[])
    {
      printf("__has_builtin(__builtin_types_compatible_p)=%d\n"
                           "__builtin_types_compatible_p(int, int)=%d\n"
                           "__builtin_types_compatible_p(int, long)=%d\n",
              __has_builtin(__builtin_types_compatible_p),
                            __builtin_types_compatible_p(int, int),
                            __builtin_types_compatible_p(int, long)) ;
    }

outputs:

    __has_builtin(__builtin_types_compatible_p)=0
    __builtin_types_compatible_p(int, int)=1
    __builtin_types_compatible_p(int, long)=0

I hope I haven't missed something blindingly obvious this time.

Thanks,

Chris




More information about the cfe-users mailing list