[Bug c/66970] Add __has_builtin() macro
felix.von.s at posteo dot de
gcc-bugzilla@gcc.gnu.org
Sat Sep 16 17:24:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66970
felix <felix.von.s at posteo dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |felix.von.s at posteo dot de
--- Comment #7 from felix <felix.von.s at posteo dot de> ---
Created attachment 42188
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42188&action=edit
Preliminary patch
Based on the already-existing __has_attribute() support, I've developed a patch
implementing this feature. Attached.
After some superficial testing (./cc1 -E), it seems to be working correctly. I
don't really have the resources to run regression tests, so I didn't (although
I think regressions would be unlikely). I also didn't write any new tests or
documentation. (I noticed __has_attribute also doesn't seem to have much of
either.)
I made the feature closely mimic The Other Compiler's behaviour: only function
built-ins are recognised. This includes generic functions like
__builtin_add_overflow and C library functions specially handled by the
front-end like printf (unless -fno-builtin is used), but excludes types like
__builtin_va_list and function-like constructs (implemented as keywords) like
__builtin_offsetof and __builtin_types_compatible_p. This is not so much of a
problem for them, since they also provide __has_feature(), __has_extension()
and __is_identifier() macros. The former has been requested in PR 60512 and
rejected; it may be reasonable to revisit the issue.
However, if more such preprocessor, er, built-ins are desired, it may start
becoming unwieldy to implement them the way I did in this patch; it involved
some amount of copy-pasting.
More information about the Gcc-bugs
mailing list