Index: gcc/testsuite/g++.dg/ext/attrib47.C
===================================================================
--- gcc/testsuite/g++.dg/ext/attrib47.C	(revision 0)
+++ gcc/testsuite/g++.dg/ext/attrib47.C	(revision 0)
@@ -0,0 +1,21 @@
+// { dg-do compile }
+// { dg-options "-O2" }
+
+class A
+{
+ public:
+  template <class T>
+  T foo(T a) __attribute__ ((noinline));
+};
+
+template <class T>
+  T A::foo(T a)
+  {
+    return a+1;
+  }
+
+int bar(A a) {
+  return a.foo(1);
+}
+
+// { dg-final { scan-assembler "_ZN1A3fooIiEET_S1_" } }
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 202261)
+++ gcc/cp/parser.c	(working copy)
@@ -16489,7 +16489,7 @@ cp_parser_init_declarator (cp_parser* parser,
       decl = grokfield (declarator, decl_specifiers,
 			initializer, !is_non_constant_init,
 			/*asmspec=*/NULL_TREE,
-			prefix_attributes);
+			chainon (prefix_attributes, attributes));
       if (decl && TREE_CODE (decl) == FUNCTION_DECL)
 	cp_parser_save_default_args (parser, decl);
     }
