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 | 950a2da1586c9cc467a47db9bfe6e7d7dbe8bc1c (patch) | |
tree | b7d287030ced0cc0cfef230468105f8b6316b721 /docs | |
parent | 8c8d967b8ab952e6072fb9aeea995fb87dd3a806 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320088 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs')
-rw-r--r-- | docs/LanguageExtensions.rst | 29 | ||||
-rw-r--r-- | docs/ReleaseNotes.rst | 5 |
2 files changed, 34 insertions, 0 deletions
diff --git a/docs/LanguageExtensions.rst b/docs/LanguageExtensions.rst index 9583a51a3b..9b407f31d9 100644 --- a/docs/LanguageExtensions.rst +++ b/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`` ------------------- diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst index 8b562bb66e..f9d4a0105f 100644 --- a/docs/ReleaseNotes.rst +++ b/docs/ReleaseNotes.rst @@ -139,6 +139,11 @@ Clang now supports the ... Attribute Changes in Clang -------------------------- +- Added the ``__has_c_attribute()`` builtin preprocessor macro which allows + users to dynamically detect whether a double square-bracket attribute is + supported in C mode. This attribute syntax can be enabled with the + ``-fdouble-square-bracket-attributes`` flag. + - The presence of __attribute__((availability(...))) on a declaration no longer implies default visibility for that declaration on macOS. |