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.
commit 8ff034b7db80ef05cd97bb4c56a1d472b990afa8 Author: Jason Merrill <ja...@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;