diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index c53acf4546dda10dffe2ff01e9c8576f2407180a..dc2c924c4728b9ec91b0877270510550079f7663 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -1336,7 +1336,7 @@ splice_template_attributes (tree *attr_p, tree decl)
   tree late_attrs = NULL_TREE;
   tree *q = &late_attrs;
 
-  if (!p)
+  if (!p || *p == error_mark_node)
     return NULL_TREE;
 
   for (; *p; )
@@ -1631,7 +1631,7 @@ void
 cplus_decl_attributes (tree *decl, tree attributes, int flags)
 {
   if (*decl == NULL_TREE || *decl == void_type_node
-      || *decl == error_mark_node)
+      || *decl == error_mark_node || attributes == error_mark_node)
     return;
 
   /* Add implicit "omp declare target" attribute if requested.  */
@@ -1668,7 +1668,7 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags)
 
   cp_check_const_attributes (attributes);
 
-  if ((flag_openmp || flag_openmp_simd) && attributes != error_mark_node)
+  if (flag_openmp || flag_openmp_simd)
     {
       bool diagnosed = false;
       for (tree *pa = &attributes; *pa; )
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr104668.C b/gcc/testsuite/g++.dg/cpp0x/pr104668.C
new file mode 100644
index 0000000000000000000000000000000000000000..c3ad33dd40b1cf58659b14f2dd9804bb0be8d305
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr104668.C
@@ -0,0 +1,13 @@
+// PR c++/104668
+// { dg-do compile { target c++11 } }
+// { dg-excess-errors "" }
+
+template <class... Ts>
+void sink(Ts...);
+template <class... Ts>
+void f(Ts...) {
+  sink([] { struct alignas:Ts) S {}; }...); }
+}
+int main() {
+  f(0);
+}