This simple patch was submitted some time ago (over 1 year), but got
lost without review. I have lately rebased and tested, and the patch
is still good. Is this OK to commit to trunk and for backport? I'd
like to port as far back as 7.

---
Fritz Reese

gcc/ChangeLog:
2020-04-01  Fritz Reese  <fore...@gcc.gnu.org>

       PR fortran/85982
       * fortran/decl.c (match_attr_spec): Lump COMP_STRUCTURE/COMP_MAP into
       attribute checking used by TYPE.

gcc/testsuite/ChangeLog:
2020-04-01  Fritz Reese  <fore...@gcc.gnu.org>

       PR fortran/85982
       * gfortran.dg/dec_structure_28.f90: New test.
commit 03ade661deaa606b005304814be9f723158ed55f
Author: Fritz Reese <fore...@gcc.gnu.org>
Date:   Fri Mar 20 13:03:42 2020 -0400

    Fix for fortran/85982

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 2f458c4faac..05503b2d3c7 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -5408,15 +5408,18 @@ match_attr_spec (void)
       if (d == DECL_STATIC && seen[DECL_SAVE])
 	continue;
 
-      if (gfc_current_state () == COMP_DERIVED
+      if (gfc_comp_struct (gfc_current_state ())
 	  && d != DECL_DIMENSION && d != DECL_CODIMENSION
 	  && d != DECL_POINTER   && d != DECL_PRIVATE
 	  && d != DECL_PUBLIC && d != DECL_CONTIGUOUS && d != DECL_NONE)
 	{
+	  const char* const state_name = (gfc_current_state () == COMP_DERIVED
+					  ? "TYPE" : "STRUCTURE");
 	  if (d == DECL_ALLOCATABLE)
 	    {
 	      if (!gfc_notify_std (GFC_STD_F2003, "ALLOCATABLE "
-				   "attribute at %C in a TYPE definition"))
+				   "attribute at %C in a %s definition",
+				   state_name))
 		{
 		  m = MATCH_ERROR;
 		  goto cleanup;
@@ -5425,7 +5428,8 @@ match_attr_spec (void)
 	  else if (d == DECL_KIND)
 	    {
 	      if (!gfc_notify_std (GFC_STD_F2003, "KIND "
-				   "attribute at %C in a TYPE definition"))
+				   "attribute at %C in a %s definition",
+				   state_name))
 		{
 		  m = MATCH_ERROR;
 		  goto cleanup;
@@ -5449,7 +5453,8 @@ match_attr_spec (void)
 	  else if (d == DECL_LEN)
 	    {
 	      if (!gfc_notify_std (GFC_STD_F2003, "LEN "
-				   "attribute at %C in a TYPE definition"))
+				   "attribute at %C in a %s definition",
+				   state_name))
 		{
 		  m = MATCH_ERROR;
 		  goto cleanup;
@@ -5472,8 +5477,8 @@ match_attr_spec (void)
 	    }
 	  else
 	    {
-	      gfc_error ("Attribute at %L is not allowed in a TYPE definition",
-			 &seen_at[d]);
+	      gfc_error ("Attribute at %L is not allowed in a %s definition",
+			 &seen_at[d], state_name);
 	      m = MATCH_ERROR;
 	      goto cleanup;
 	    }

Reply via email to