Hi,

On 11/01/2018 21:33, Jason Merrill wrote:
On 01/10/2018 06:50 PM, Paolo Carlini wrote:
thus the below is a rather "dull" solution at the level of cplus_decl_attributes itself: cp_check_const_attributes is tweaked to check for error_mark_node at each outer iteration

This shouldn't be necessary; we should have returned error_mark_node for the attribute list rather than append it to something else, in which case the existing check for attributes == error_mark_node would have done the job.
Indeed. That seems the most straightforward way to approach the issue. Thanks.

In grokdeclarator we could either explicitly assign error_mark_node to *attrlist (instead of chaining) or simply drop the erroneous declarator->std_attributes. Both solutions appear to work fine in practice, pass testing.

Paolo.

/////////////////////
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 256556)
+++ cp/decl.c   (working copy)
@@ -11487,9 +11487,15 @@ grokdeclarator (const cp_declarator *declarator,
       && declarator->kind == cdk_id
       && declarator->std_attributes
       && attrlist != NULL)
-    /* [dcl.meaning]/1: The optional attribute-specifier-seq following
-       a declarator-id appertains to the entity that is declared.  */
-    *attrlist = chainon (*attrlist, declarator->std_attributes);
+    {
+      /* [dcl.meaning]/1: The optional attribute-specifier-seq following
+        a declarator-id appertains to the entity that is declared.  */
+      if (declarator->std_attributes != error_mark_node)
+       *attrlist = chainon (*attrlist, declarator->std_attributes);
+      else
+       /* We should have already diagnosed the issue (c++/78344).  */
+       *attrlist = error_mark_node;
+    }
 
   /* Handle parameter packs. */
   if (parameter_pack_p)
Index: testsuite/g++.dg/cpp0x/alignas13.C
===================================================================
--- testsuite/g++.dg/cpp0x/alignas13.C  (nonexistent)
+++ testsuite/g++.dg/cpp0x/alignas13.C  (working copy)
@@ -0,0 +1,5 @@
+// PR c++/78344
+// { dg-do compile { target c++11 } }
+
+alignas(double) int f alignas;         // { dg-error "30:expected '\\('" }
+alignas(double) int g alignas(double;  // { dg-error "37:expected '\\)'" }
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 256556)
+++ cp/decl.c   (working copy)
@@ -11486,6 +11486,8 @@ grokdeclarator (const cp_declarator *declarator,
   if (declarator
       && declarator->kind == cdk_id
       && declarator->std_attributes
+      /* We should have already diagnosed the issue (c++/78344).  */
+      && declarator->std_attributes != error_mark_node
       && attrlist != NULL)
     /* [dcl.meaning]/1: The optional attribute-specifier-seq following
        a declarator-id appertains to the entity that is declared.  */
Index: testsuite/g++.dg/cpp0x/alignas13.C
===================================================================
--- testsuite/g++.dg/cpp0x/alignas13.C  (nonexistent)
+++ testsuite/g++.dg/cpp0x/alignas13.C  (working copy)
@@ -0,0 +1,5 @@
+// PR c++/78344
+// { dg-do compile { target c++11 } }
+
+alignas(double) int f alignas;         // { dg-error "30:expected '\\('" }
+alignas(double) int g alignas(double;  // { dg-error "37:expected '\\)'" }

Reply via email to