diff options
author | Martin Sebor <msebor@redhat.com> | 2019-10-28 22:46:28 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-10-28 16:46:28 -0600 |
commit | ad1539d5555a161cf6851de8995641d6dfe792d9 (patch) | |
tree | e56e9d15ba5ff4476a38e5269c6163b5dc6a36e9 /gcc/doc/cpp.texi | |
parent | 48b2123f6336ba6c06846d7c8b60bd14eaeae7ec (diff) | |
download | gcc-ad1539d5555a161cf6851de8995641d6dfe792d9.zip gcc-ad1539d5555a161cf6851de8995641d6dfe792d9.tar.gz gcc-ad1539d5555a161cf6851de8995641d6dfe792d9.tar.bz2 |
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.
From-SVN: r277544
Diffstat (limited to 'gcc/doc/cpp.texi')
-rw-r--r-- | gcc/doc/cpp.texi | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index f2de39a..bd741ce 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -3159,6 +3159,7 @@ directive}: @samp{#if}, @samp{#ifdef} or @samp{#ifndef}. * Elif:: * @code{__has_attribute}:: * @code{__has_cpp_attribute}:: +* @code{__has_builtin}:: * @code{__has_include}:: @end menu @@ -3478,6 +3479,33 @@ information including the dates of the introduction of current standard attributes, see @w{@uref{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations/, SD-6: SG10 Feature Test Recommendations}}. +@node @code{__has_builtin} +@subsection @code{__has_builtin} +@cindex @code{__has_builtin} + +The special operator @code{__has_builtin (@var{operand})} may be used in +constant integer contexts and in preprocessor @samp{#if} and @samp{#elif} +expressions to test whether the symbol named by its @var{operand} is +recognized as a built-in function by GCC in the current language and +conformance mode. It evaluates to a constant integer with a nonzero +value if the argument refers to such a function, and to zero otherwise. +The operator may also be used in preprocessor @samp{#if} and @samp{#elif} +expressions. The @code{__has_builtin} operator by itself, without any +@var{operand} or parentheses, acts as a predefined macro so that support +for it can be tested in portable code. Thus, the recommended use of +the operator is as follows: + +@smallexample +#if defined __has_builtin +# if __has_builtin (__builtin_object_size) +# define builtin_object_size(ptr) __builtin_object_size (ptr, 2) +# endif +#endif +#ifndef builtin_object_size +# define builtin_object_size(ptr) ((size_t)-1) +#endif +@end smallexample + @node @code{__has_include} @subsection @code{__has_include} @cindex @code{__has_include} |