diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2017-12-07 21:37:49 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2017-12-07 21:37:49 +0000 |
commit | 48f5f4d895ecada915677f528d493814a76e890d (patch) | |
tree | f4d95612ffc58c9a8f327bcd2f448e64bb3b33c9 /clang/docs/LanguageExtensions.rst | |
parent | 095d4ea4bf4eb13efeeed8b0f1faf93e205ab021 (diff) | |
download | bcm5719-llvm-48f5f4d895ecada915677f528d493814a76e890d.tar.gz bcm5719-llvm-48f5f4d895ecada915677f528d493814a76e890d.zip |
Add support for the __has_c_attribute builtin preprocessor macro.
This behaves similar to the __has_cpp_attribute builtin macro in that it allows users to detect whether an attribute is supported with the [[]] spelling syntax, which can be enabled in C with -fdouble-square-bracket-attributes.
llvm-svn: 320088
Diffstat (limited to 'clang/docs/LanguageExtensions.rst')
-rw-r--r-- | clang/docs/LanguageExtensions.rst | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 9583a51a3ba..9b407f31d97 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -139,6 +139,35 @@ and following ``__`` (double underscore) to avoid interference from a macro with the same name. For instance, ``gnu::__const__`` can be used instead of ``gnu::const``. +``__has_c_attribute`` +--------------------- + +This function-like macro takes a single argument that is the name of an +attribute exposed with the double square-bracket syntax in C mode. The argument +can either be a single identifier or a scoped identifier. If the attribute is +supported, a nonzero value is returned. If the attribute is not supported by the +current compilation target, this macro evaluates to 0. It can be used like this: + +.. code-block:: c + + #ifndef __has_c_attribute // Optional of course. + #define __has_c_attribute(x) 0 // Compatibility with non-clang compilers. + #endif + + ... + #if __has_c_attribute(fallthrough) + #define FALLTHROUGH [[fallthrough]] + #else + #define FALLTHROUGH + #endif + ... + +The attribute identifier (but not scope) can also be specified with a preceding +and following ``__`` (double underscore) to avoid interference from a macro with +the same name. For instance, ``gnu::__const__`` can be used instead of +``gnu::const``. + + ``__has_attribute`` ------------------- |