===================================================================
@@ -1345,10 +1345,12 @@ cplus_decl_attributes (tree *decl, tree attributes
if (check_for_bare_parameter_packs (attributes))
return;
- save_template_attributes (&attributes, decl);
+ if (attributes != error_mark_node)
+ save_template_attributes (&attributes, decl);
}
- cp_check_const_attributes (attributes);
+ if (attributes != error_mark_node)
+ cp_check_const_attributes (attributes);
if (TREE_CODE (*decl) == TEMPLATE_DECL)
decl = &DECL_TEMPLATE_RESULT (*decl);
===================================================================
@@ -21458,6 +21458,8 @@ cp_parser_std_attribute_spec (cp_parser *parser)
alignas_expr =
cp_parser_assignment_expression (parser, /*cast_p=*/false,
/**cp_id_kind=*/NULL);
+ if (alignas_expr == error_mark_node)
+ cp_parser_skip_to_end_of_statement (parser);
if (alignas_expr == NULL_TREE
|| alignas_expr == error_mark_node)
return alignas_expr;
===================================================================
@@ -0,0 +1,12 @@
+// PR c++/58584
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+ int i alignas(this); // { dg-error "17:invalid use of 'this'" }
+};
+
+template<int> struct B
+{
+ int j alignas(this); // { dg-error "17:invalid use of 'this'" }
+};