This is a trivial patch that enforces the requirement that PDT parameters
do not have an access specification and appear before a PRIVATE statement
within the derived type.

Regtests on FC42/x86_64. OK for mainline?

Paul
diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index 300a7a36fbd..dfd0bdd32d5 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -3961,6 +3961,22 @@ parse_derived (void)
 	case ST_PROCEDURE:
 	  accept_statement (st);
 	  seen_component = 1;
+	  for (c = gfc_current_block ()->components; c; c = c->next)
+	    if (!c->next && (c->attr.pdt_kind || c->attr.pdt_len))
+	      {
+		if (c->attr.access != ACCESS_UNKNOWN)
+		  {
+		    gfc_error ("Access specification of a type parameter at "
+			       "%C is not allowed");
+		    break;
+		  }
+		if (seen_private)
+		  {
+		    gfc_error ("The type parameter at %C must come before a "
+			       "PRIVATE statement");
+		    break;
+		  }
+	      }
 	  break;
 
 	case ST_FINAL:
diff --git a/gcc/testsuite/gfortran.dg/pdt_38.f03 b/gcc/testsuite/gfortran.dg/pdt_38.f03
new file mode 100644
index 00000000000..99bdcbf6e00
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_38.f03
@@ -0,0 +1,21 @@
+! { dg-do compile )
+!
+! Test the fix for pr84122
+!
+! Contributed by Neil Carlson  <neil.n.carl...@gmail.com>
+!
+module mod
+type foo(idim)
+  integer, len, private :: idim ! { dg-error "PRIVATE attribute conflicts with LEN" }
+  private
+  integer :: array(idim)        ! { dg-error "must be constant" }
+end type
+end module
+
+module bar
+type foo(idim)
+  private
+  integer,len :: idim         ! { dg-error "must come before a PRIVATE statement" }
+  integer :: array(idim)
+end type
+end module

Attachment: Change.Logs
Description: Binary data

Reply via email to