2025-09-05 Paul Thomas <pault@gcc.gnu.org>
gcc/fortran
PR fortran/83762
PR fortran/102457
* decl.cc (gfc_get_pdt_instance): Check that variable PDT parm
expressions are of type integer. Note that the symbol must be
tested since the expression often appears as BT_PROCEDURE.
gcc/testsuite/
PR fortran/83762
PR fortran/102457
* gfortran.dg/pdt_44.f03: New test.
* gfortran.dg/pr95090.f90: Give the PDT parameter a value to
suppress the type error.
}
}
+ 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. */
--- /dev/null
+! { 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
contains
subroutine s2345678901234567890123456789012345678901234567890123456789_123
type(t2345678901234567890123456789012345678901234567890123456789_123 &
- (n2345678901234567890123456789012345678901234567890123456789_123)) :: &
+ (n2345678901234567890123456789012345678901234567890123456789_123 = 4)) :: &
z2345678901234567890123456789012345678901234567890123456789_123
end
end