[C++ Patch] PR 58584

Paolo Carlini paolo.carlini@oracle.com
Thu Oct 3 01:03:00 GMT 2013


Hi,

to avoid these ICE on invalid with C++11 alignas, we can simply avoid 
calling save_template_attributes and cp_check_const_attributes when 
something went wrong and attributes is error_mark_node.

The parser bit just tidies the diagnostic, ie, avoids redundant messages 
about semicolons, etc.

Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
-------------- next part --------------
/cp
2013-10-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58584
	* decl2.c (cplus_decl_attributes): Correctly handle error_mark_node as
	attributes argument.
	* parser.c (cp_parser_std_attribute_spec): When alignas_expr is an
	error_mark_node call cp_parser_skip_to_end_of_statement.

/testsuite
2013-10-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58584
	* g++.dg/cpp0x/gen-attrs-55.C: New.
-------------- next part --------------
Index: cp/decl2.c
===================================================================
--- cp/decl2.c	(revision 203139)
+++ cp/decl2.c	(working copy)
@@ -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);
Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 203139)
+++ cp/parser.c	(working copy)
@@ -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;
Index: testsuite/g++.dg/cpp0x/gen-attrs-55.C
===================================================================
--- testsuite/g++.dg/cpp0x/gen-attrs-55.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/gen-attrs-55.C	(working copy)
@@ -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'" }
+};


More information about the Gcc-patches mailing list