C++ PATCH for c++/85062, ICE with variadic alignas in wrong place

Message ID CADzB+2kMDi6GD9K8G-LcYrDWt2A8t3ZKndeP1SzoJ_2_tRAtqA@mail.gmail.com
State New
Headers show
Series
  • C++ PATCH for c++/85062, ICE with variadic alignas in wrong place
Related show

Commit Message

Jason Merrill March 26, 2018, 3:57 p.m.
We've been passing C++11 attributes that appertain to a type-specifier
down to decl_attributes, which gave a warning and ignored them, but it
was confused by the pack expansion.  It seems easiest to deal with
this by ignoring them directly in grokdeclarator.

Tested x86_64-pc-linux-gnu, applying to trunk.

Comments

Jason Merrill March 26, 2018, 4:51 p.m. | #1
On Mon, Mar 26, 2018 at 11:57 AM, Jason Merrill <jason@redhat.com> wrote:
> We've been passing C++11 attributes that appertain to a type-specifier

> down to decl_attributes, which gave a warning and ignored them, but it

> was confused by the pack expansion.  It seems easiest to deal with

> this by ignoring them directly in grokdeclarator.


I suppose it would make sense to allow [[gnu::vector_size]] in this
position, but that would be a change from the status quo, and it
doesn't seem urgent.

Jason

Patch

commit 8ff034b7db80ef05cd97bb4c56a1d472b990afa8
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Mar 26 11:16:04 2018 -0400

            PR c++/85062 - ICE with alignas in wrong place.
    
            * decl.c (grokdeclarator): Ignore attributes on type-specifiers
            here.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 96d4b723b4a..ba456737e0e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10946,10 +10946,10 @@  grokdeclarator (const cp_declarator *declarator,
 
   if (declspecs->std_attributes)
     {
-      /* Apply the c++11 attributes to the type preceding them.  */
-      input_location = declspecs->locations[ds_std_attribute];
-      decl_attributes (&type, declspecs->std_attributes, 0);
-      input_location = saved_loc;
+      location_t attr_loc = declspecs->locations[ds_std_attribute];
+      if (warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
+	inform (attr_loc, "an attribute that appertains to a type-specifier "
+		"is ignored");
     }
 
   /* Determine the type of the entity declared by recurring on the
diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas16.C b/gcc/testsuite/g++.dg/cpp0x/alignas16.C
new file mode 100644
index 00000000000..7c349929786
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alignas16.C
@@ -0,0 +1,9 @@ 
+// PR c++/85062
+// { dg-do compile { target c++11 } }
+
+template<typename... T> struct A
+{
+  int alignas(T...) i;		// { dg-warning "ignored" }
+};
+
+A<int> a;