Hi All,

This is another straightforward patch that detects variables with
non-integer type being used as PDT parameters. Note that much of the time,
when being parsed, variable expressions have type BT_PROCEDURE and so the
type of the symbol must be checked. The parameter fed to the PDT
in pr95090.f90 was of unknown type and so that has been fixed by giving it
a value.

Regtested on FC42/x86_64. OK for mainline?

Paul

Attachment: Change.Logs
Description: Binary data

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 1e91b57aa96..9fb04ac59c5 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -3952,6 +3952,16 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym,
 	    }
 	}
 
+      if (kind_expr && kind_expr->expr_type == EXPR_VARIABLE
+	  && kind_expr->ts.type != BT_INTEGER
+	  && kind_expr->symtree->n.sym->ts.type != BT_INTEGER)
+	{
+	  gfc_error ("The type parameter expression at %L must be of INTEGER "
+		     "type and not %s", &kind_expr->where,
+		     gfc_basic_typename (kind_expr->symtree->n.sym->ts.type));
+	  goto error_return;
+	}
+
       /* Store the current parameter expressions in a temporary actual
 	 arglist 'list' so that they can be substituted in the corresponding
 	 expressions in the PDT instance.  */
diff --git a/gcc/testsuite/gfortran.dg/pdt_44.f03 b/gcc/testsuite/gfortran.dg/pdt_44.f03
new file mode 100644
index 00000000000..459001cab09
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_44.f03
@@ -0,0 +1,28 @@
+! { dg-do compile }
+!
+! Test the fix for PRs83762 and 102457, in which type parameter expressions that
+! are not of INTEGER type were either not being diagnosed or were inadequately
+! diagnosed.
+!
+! PR83762
+module bar
+  implicit none
+  type :: foo(n)
+     integer, len :: n=10
+  end type foo
+contains
+  subroutine main
+    type(foo(undefined)) :: x ! { dg-error "must be of INTEGER type and not UNKNOWN" }
+  end subroutine main
+end module bar
+
+! PR102457
+subroutine s
+   real :: m = 2
+   type t(n)
+      integer, len :: n = 1
+      character(n*n) :: c
+   end type
+   type(t(m)) :: x ! { dg-error "must be of INTEGER type and not REAL" }
+   call h(x)
+end
diff --git a/gcc/testsuite/gfortran.dg/pr95090.f90 b/gcc/testsuite/gfortran.dg/pr95090.f90
index ec77802ec51..714802fcbd9 100644
--- a/gcc/testsuite/gfortran.dg/pr95090.f90
+++ b/gcc/testsuite/gfortran.dg/pr95090.f90
@@ -13,7 +13,7 @@ module m2345678901234567890123456789012345678901234567890123456789_123
 contains
   subroutine s2345678901234567890123456789012345678901234567890123456789_123
     type(t2345678901234567890123456789012345678901234567890123456789_123 &
-        (n2345678901234567890123456789012345678901234567890123456789_123)) :: &
+        (n2345678901234567890123456789012345678901234567890123456789_123 = 4)) :: &
          z2345678901234567890123456789012345678901234567890123456789_123
    end
 end

Reply via email to