Bug 86288 - Recognize __gnu and/or __gnu__ as attribute-namespace
Summary: Recognize __gnu and/or __gnu__ as attribute-namespace
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 enhancement
Target Milestone: 8.3
Assignee: Jakub Jelinek
URL: https://gcc.gnu.org/ml/gcc-patches/20...
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-06-22 21:16 UTC by Jonathan Wakely
Modified: 2019-05-22 08:09 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-10-17 00:00:00


Attachments
gcc9-pr86288.patch (907 bytes, patch)
2018-10-17 13:05 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2018-06-22 21:16:08 UTC
Libstdc++ can't use C++11 attribute syntax for GNU-specific attributes like [[gnu::nonnull]], because those identifiers are not reserved names. We can use __nonnull__ but only "gnu" is recognized for the namespace.

Could G++ be extended to also accept [[__gnu__::__nonnull__]] ?

__gnu__ doesn't seem to clash with anything predefined by GCC, or defined by Glibc.
Comment 1 Jakub Jelinek 2018-10-17 13:01:10 UTC
Unrelated note, we even ICE on
int f [[using gnu : __aligned__(alignof(int))]];
Comment 2 Jakub Jelinek 2018-10-17 13:05:18 UTC
Created attachment 44846 [details]
gcc9-pr86288.patch

Untested patch with implementation for this enhancement request as well as fix for the above mentioned ICE (the latter should be backported I guess).
Comment 3 Martin Sebor 2018-10-17 18:25:54 UTC
If both __gnu__ and __gnu are accepted, should both __aligned__ and __aligned also be?  If not, then should only __gnu__ be accepted?
Comment 4 Jonathan Wakely 2018-10-17 19:06:10 UTC
I think Jakub's patch does only allow __gnu__, using the same canonicalization for attribute-namespaces as for attributes.
Comment 5 Jonathan Wakely 2018-10-24 12:50:23 UTC
Clang has now implemented this as a special case, only recognizing "__gnu__" as a synonym for the "gnu" attribute-namespace. That's fine for libstdc++'s purposes, as I don't expect we'll start using any other vendor attributes.

EDG have also been told about this, so compilers based on their front end should also be able to recognize [[__gnu__::__blah__]] at some point.
Comment 6 Jakub Jelinek 2018-10-24 19:39:55 UTC
Author: jakub
Date: Wed Oct 24 19:39:23 2018
New Revision: 265470

URL: https://gcc.gnu.org/viewcvs?rev=265470&root=gcc&view=rev
Log:
	PR c++/86288
	* parser.c (cp_parser_std_attribute): Canonicalize attr_ns, and when
	:: is not present and attr_ns non-NULL, canonicalize also attr_id.
	(cp_parser_attribute_spec): Fix comment typo.

	* g++.dg/cpp0x/gen-attrs-66.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/gen-attrs-66.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2018-11-05 14:09:43 UTC
Author: jakub
Date: Mon Nov  5 14:09:10 2018
New Revision: 265803

URL: https://gcc.gnu.org/viewcvs?rev=265803&root=gcc&view=rev
Log:
	Backported from mainline
	2018-10-24  Jakub Jelinek  <jakub@redhat.com>

	PR c++/86288
	* parser.c (cp_parser_std_attribute): Canonicalize attr_ns, and when
	:: is not present and attr_ns non-NULL, canonicalize also attr_id.
	(cp_parser_attribute_spec): Fix comment typo.

	* g++.dg/cpp0x/gen-attrs-66.C: New test.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/cpp0x/gen-attrs-66.C
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/parser.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 8 Jonathan Wakely 2019-05-22 08:09:39 UTC
Fixed for 8.3 and 9.1