C++ Logo

sg10

Advanced search

Re: [SG10] __has_cpp_attribute example

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Wed, 12 Oct 2016 12:55:14 +0100
On 12 October 2016 at 12:51, Aaron Ballman <aaron_at_[hidden]> wrote:
> On Wed, Oct 12, 2016 at 6:55 AM, Jonathan Wakely <cxx_at_[hidden]> 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
>
> I think your modifications would be reasonable, though there are other
> methods to decide if it's available (such as checking compiler
> macros).

Indeed, and I wondered if that's the intention. My version would still
allow that, by adding an #else branch to the #ifdef. I don't know if
SD-6 (which is all about portable ways to detect such things) wants to
show/suggest/encourage that though :-)

Received on 2016-10-12 13:55:35