[SG10] __has_cpp_attribute example
Richard Smith
richard at metafoo.co.uk
Wed Oct 12 21:36:08 CEST 2016
On Wed, Oct 12, 2016 at 3:55 AM, Jonathan Wakely <cxx at kayari.org> wrote:
> The SD-6 draft has
>
> [3.3.6] Example
>
> This demonstrates a way to use the attribute [[deprecated]] only if it
> is available.
>
> #ifdef __has_cpp_attribute
> # if __has_cpp_attribute(deprecated)
> # define ATTR_DEPRECATED(msg) [[deprecated(msg)]]
> # else
> # define ATTR_DEPRECATED(msg)
> # endif
> #endif
>
>
>
> This leaves ATTR_DEPRECATED undefined if the compiler doesn't support
> the __has_cpp_attribute macro, is that intended? Unless the idea is
> that some other method would be used to decide if it's available, it
> should be something like:
>
> #ifdef __has_cpp_attribute
> # if __has_cpp_attribute(deprecated)
> # define ATTR_DEPRECATED(msg) [[deprecated(msg)]]
> # endif
> #endif
> #ifndef ATTR_DEPRECATED(msg)
> # define ATTR_DEPRECATED(msg)
> #endif
>
The usage model we've always documented for these __has_* macros in Clang
is:
#ifndef __has_cpp_attribute
# define __has_cpp_attribute(x) 0
#endif
#if __has_cpp_attribute(deprecated)
# define ATTR_DEPRECATED(msg) [[deprecated(msg)]]
#else
# define ATTR_DEPRECATED(msg)
#endif
Would it also be useful to mention that the grammar term
> "attribute-token" allows scoped attributes, such as foo::bar, so that
> non-standard attributes can be tested the same way?
> _______________________________________________
> Features mailing list
> Features at isocpp.open-std.org
> http://www.open-std.org/mailman/listinfo/features
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open-std.org/pipermail/features/attachments/20161012/fc33fb4a/attachment.html
More information about the Features
mailing list