diff mbox series

[C++] Allow __ prefix+suffix on C++11 attribute namespaces (PR c++/86288)

Message ID 20181017224500.GG11625@tucnak
State New
Headers show
Series [C++] Allow __ prefix+suffix on C++11 attribute namespaces (PR c++/86288) | expand

Commit Message

Jakub Jelinek Oct. 17, 2018, 10:45 p.m. UTC
Hi!

As mentioned in the PR, for use in headers for the same reason like we
support __aligned__ form next to aligned (user defining such a macro) this
patch allows to mangle the scope the same way.

In addition to that, it fixes an ICE, where because we didn't canonicalize
the attribute name in [[using gnu : __aligned__(4)]] we'd ICE on some of the
GNU attributes.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Is a partial backport (just add
      attr_id = canonicalize_attr_name (attr_id);
in the else if (attr_ns) case plus the non-__gnu__ lines from the testcase)
ok for 7/8 release branches where it ICEs?

2018-10-18  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.


	Jakub

Comments

Jakub Jelinek Oct. 18, 2018, 7:35 a.m. UTC | #1
On Thu, Oct 18, 2018 at 12:45:00AM +0200, Jakub Jelinek wrote:
> Is a partial backport (just add
>       attr_id = canonicalize_attr_name (attr_id);
> in the else if (attr_ns) case plus the non-__gnu__ lines from the testcase)
> ok for 7/8 release branches where it ICEs?

Small clarification, only needs to go to 8.x, 7.x compiled it fine, it
got broken with r250911.

	Jakub
Jason Merrill Oct. 24, 2018, 7 p.m. UTC | #2
On 10/17/18 6:45 PM, Jakub Jelinek wrote:
> As mentioned in the PR, for use in headers for the same reason like we
> support __aligned__ form next to aligned (user defining such a macro) this
> patch allows to mangle the scope the same way.
> 
> In addition to that, it fixes an ICE, where because we didn't canonicalize
> the attribute name in [[using gnu : __aligned__(4)]] we'd ICE on some of the
> GNU attributes.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> Is a partial backport (just add
>        attr_id = canonicalize_attr_name (attr_id);
> in the else if (attr_ns) case plus the non-__gnu__ lines from the testcase)
> ok for 7/8 release branches where it ICEs?

If a backport seems useful, go ahead and backport the whole patch.

Jason
diff mbox series

Patch

--- gcc/cp/parser.c.jj	2018-10-15 18:05:42.562236914 +0200
+++ gcc/cp/parser.c	2018-10-17 14:45:25.205543993 +0200
@@ -25327,14 +25327,19 @@  cp_parser_std_attribute (cp_parser *pars
 	  return error_mark_node;
 	}
 
+      attr_ns = canonicalize_attr_name (attr_ns);
       attr_id = canonicalize_attr_name (attr_id);
       attribute = build_tree_list (build_tree_list (attr_ns, attr_id),
 				   NULL_TREE);
       token = cp_lexer_peek_token (parser->lexer);
     }
   else if (attr_ns)
-    attribute = build_tree_list (build_tree_list (attr_ns, attr_id),
-				 NULL_TREE);
+    {
+      attr_ns = canonicalize_attr_name (attr_ns);
+      attr_id = canonicalize_attr_name (attr_id);
+      attribute = build_tree_list (build_tree_list (attr_ns, attr_id),
+				   NULL_TREE);
+    }
   else
     {
       attr_id = canonicalize_attr_name (attr_id);
@@ -25526,7 +25531,7 @@  cp_parser_std_attribute_spec (cp_parser
 	  || !cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE))
 	cp_parser_skip_to_end_of_statement (parser);
       else
-	/* Warn about parsing c++11 attribute in non-c++1 mode, only
+	/* Warn about parsing c++11 attribute in non-c++11 mode, only
 	   when we are sure that we have actually parsed them.  */
 	maybe_warn_cpp0x (CPP0X_ATTRIBUTES);
     }
--- gcc/testsuite/g++.dg/cpp0x/gen-attrs-66.C.jj	2018-10-17 14:47:15.493686357 +0200
+++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-66.C	2018-10-17 15:00:30.450240982 +0200
@@ -0,0 +1,12 @@ 
+// PR c++/86288
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wattributes" }
+
+int a [[gnu::aligned(alignof(int))]];
+int b [[gnu::__aligned__(alignof(int))]];
+int c [[__gnu__::aligned(alignof(int))]];
+int d [[__gnu__::__aligned__(alignof(int))]];
+int e [[using gnu : aligned(alignof(int))]];		// { dg-warning "attribute using prefix only available" "" { target c++14_down } }
+int f [[using gnu : __aligned__(alignof(int))]];	// { dg-warning "attribute using prefix only available" "" { target c++14_down } }
+int g [[using __gnu__ : aligned(alignof(int))]];	// { dg-warning "attribute using prefix only available" "" { target c++14_down } }
+int h [[using __gnu__ : __aligned__(alignof(int))]];	// { dg-warning "attribute using prefix only available" "" { target c++14_down } }