[Bug c++/81513] __has_cpp_attribute returns non-zero in C++03 mode, but attributes don't work

2018-07-10 Thread proski at gnu dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81513

Pavel Roskin  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #5 from Pavel Roskin  ---
After reading the discussion, it became clear to me that it's a corner case
that is not really worth spending more time on. I'm marking the issue as
resolved.

[Bug c++/81513] __has_cpp_attribute returns non-zero in C++03 mode, but attributes don't work

2017-07-24 Thread sch...@linux-m68k.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81513

--- Comment #4 from Andreas Schwab  ---
> #if __cpp_attributes >= 200809 && defined(__has_cpp_attribute) \
>   && __has_cpp_attribute(maybe_unused)

This will result in a syntax error if the compiler does not support
__has_cpp_attribute.  You need to separate the check from the use of the macro.

[Bug c++/81513] __has_cpp_attribute returns non-zero in C++03 mode, but attributes don't work

2017-07-24 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81513

Jonathan Wakely  changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org

--- Comment #3 from Jonathan Wakely  ---
(In reply to Pavel Roskin from comment #2)
> __has_cpp_attribute is not supposed to check if the functionality is
> available somehow using some other approaches and keywords. It is supposed
> to check if the functionality is available as an attribute.

__has_cpp_attribute(X) tells you if X is a valid attribute. To know if you can
also use the C++11 attribute syntax you can use __cpp_attributes >= 200809.

So I would write your test as:

#if __cpp_attributes >= 200809 && defined(__has_cpp_attribute) \
  && __has_cpp_attribute(maybe_unused)
# define __maybe_unused [[maybe_unused]]
#endif

#ifndef __maybe_unused
# define __maybe_unused
#endif

That will make it work in C++03 mode.

If your bug report is that __has_cpp_attribute doesn't tell you if C++11
attribute syntax is supported, then the bug report is invalid. You should be
using __cplusplus >= 201103L for that (or the non-standard but WG21-approved
__cpp_attributes >= 200809), not assuming that the existence of
__cpp_has_attribute implies C++11 attributes work.

The reason is that you can use __has_cpp_attribute(gnu::unused) in C++03 mode
to test if __attribute__((unused)) will work.

Maybe we should make __has_cpp_attribute false in C++03 mode for any attribute
without the gnu:: prefix, if such attributes really aren't usable without C++11
syntax.

> Even is there is some alternative notation for C++03, I expect the attribute
> name to be the same. If __has_cpp_attribute(maybe_unused) is set to a
> non-zero value, I expect to use "maybe_unused", not "unused".

I'm not disagreeing, I was only observing that the other attribute name does
work as __attribute__((maybe_unused)). But I think that's because the correct
test for that would be __has_cpp_attribute(gnu::maybe_unused) (which is false,
as expected).


We should probably document the behaviour of __has_cpp_attribute and how it
interacts with GNU-style attributes as well as C++11-style attributes.

[Bug c++/81513] __has_cpp_attribute returns non-zero in C++03 mode, but attributes don't work

2017-07-24 Thread proski at gnu dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81513

--- Comment #2 from Pavel Roskin  ---
__has_cpp_attribute is not supposed to check if the functionality is available
somehow using some other approaches and keywords. It is supposed to check if
the functionality is available as an attribute.

Even is there is some alternative notation for C++03, I expect the attribute
name to be the same. If __has_cpp_attribute(maybe_unused) is set to a non-zero
value, I expect to use "maybe_unused", not "unused".

[Bug c++/81513] __has_cpp_attribute returns non-zero in C++03 mode, but attributes don't work

2017-07-22 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81513

--- Comment #1 from Jonathan Wakely  ---
The C++11 attribute syntax isn't supported in C++03 mode, but the noreturn
attribute is supported using the GNU attribute syntax (and has been for years)
so it's right for that to be non-zero. I'm not sure why maybe_unused is
non-zero but doesn't work. __attribute__((unused)) works, but
__attribute__((maybe_unused)) doesn't.