On 10/1/19 11:16 AM, Martin Sebor wrote:
> Attached is an implementation of the __has_builtin special
> preprocessor operator/macro analogous to __has_attribute and
> (hopefully) compatible with the synonymous Clang feature (I
> couldn't actually find tests for it in the Clang test suite
> but if someone points me at them I'll verify it).
>
> Tested on x86_64-linux.
>
> Martin
>
> PS I couldn't find an existing API to test whether a reserved
> symbol like __builtin_offsetof is a function-like built-in so
> I hardwired the tests for C and C++ into the new names_builtin_p
> functions. I don't like this very much because the next time
> such an operator is added there is nothing to remind us to update
> the functions. Adding a flag to the c_common_reswords array would
> solve the problem but at the expense of a linear search through
> it. Does anyone have a suggestion for how to do this better?
>
> gcc-66970.diff
>
> PR c/66970 - Add __has_builtin() macro
>
> gcc/ChangeLog:
> PR c/66970
> * doc/cpp.texi (__has_builtin): Document.
> * doc/extend.texi (__builtin_frob_return_addr): Correct spelling.
>
> gcc/c/ChangeLog:
>
> PR c/66970
> * c-decl.c (names_builtin_p): Define a new function.
>
> gcc/c-family/ChangeLog:
>
> PR c/66970
> * c-common.c (c_common_nodes_and_builtins): Call c_define_builtins
> even when only preprocessing.
> * c-common.h (names_builtin_p): Declare new function.
> * c-lex.c (init_c_lex): Set has_builtin.
> (c_common_has_builtin): Define a new function.
> * c-ppoutput.c (init_pp_output): Set has_builtin.
>
> gcc/cp/ChangeLog:
>
> PR c/66970
> * cp-objcp-common.c (names_builtin_p): Define new function.
>
> gcc/testsuite/ChangeLog:
>
> PR c/66970
> * c-c++-common/cpp/has-builtin-2.c: New test.
> * c-c++-common/cpp/has-builtin-3.c: New test.
> * c-c++-common/cpp/has-builtin.c: New test.
>
> libcpp/ChangeLog:
>
> PR c/66970
> * include/cpplib.h (cpp_builtin_type): Add BT_HAS_BUILTIN.
> (cpp_callbacks::has_builtin): Declare new member.
> * init.c (builtin_array): Add an element for BT_HAS_BUILTIN.
> (cpp_init_special_builtins): Handle BT_HAS_BUILTIN.
> * macro.c (_cpp_builtin_macro_text): Same.
> * traditional.c: Same.
OK
jeff