Hi All, These fixes are minor on the scale of things and fix no fewer than three problems (2 PRs):
(i) PR95543 exposed two separate bugs. The first was that default initializer expressions that are not constants, were not being expanded so that the name of the PDT instance could not be generated and an ICE was caused downstream. This is fixed by the first two chunks in the patch. Once this was fixed, comparison with other brands showed the testcase failing at the declaration " type(t()) :: z" because the type specification list is empty, contrary to F2023 R755: type-param-spec is [ keyword = ] type-param-value. This is fixed by the chunk in primary.cc. (ii) PR103748 was due to type spec lists being applied to derived types that are not parameterized. This is fixed by the third chunk. Regtests with FC42/x86_64 - OK for mainline? Paul
Change.Logs
Description: Binary data
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index ab43cec6f4b..e97bc0a56a0 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -3855,7 +3855,7 @@ insert_parameter_exprs (gfc_expr* e, gfc_symbol* sym ATTRIBUTE_UNUSED,
if (strcmp (e->symtree->n.sym->name, param->name) == 0)
break;
- if (param)
+ if (param && param->expr)
{
copy = gfc_copy_expr (param->expr);
*e = *copy;
@@ -4028,6 +4028,12 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym,
/* Try simplification even for LEN expressions. */
bool ok;
gfc_resolve_expr (kind_expr);
+
+ if (c1->attr.pdt_kind
+ && kind_expr->expr_type != EXPR_CONSTANT
+ && type_param_spec_list)
+ gfc_insert_parameter_exprs (kind_expr, type_param_spec_list);
+
ok = gfc_simplify_expr (kind_expr, 1);
/* Variable expressions seem to default to BT_PROCEDURE.
TODO find out why this is and fix it. */
@@ -4810,6 +4816,16 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag)
return MATCH_ERROR;
}
+ if (dt_sym && decl_type_param_list
+ && dt_sym->attr.flavor == FL_DERIVED
+ && !dt_sym->attr.pdt_type
+ && !dt_sym->attr.pdt_template)
+ {
+ gfc_error ("Type %qs is not parameterized and so the type parameter spec "
+ "list at %C may not appear", dt_sym->name);
+ return MATCH_ERROR;
+ }
+
if (sym && sym->attr.flavor == FL_DERIVED
&& sym->attr.pdt_template
&& gfc_current_state () != COMP_DERIVED)
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index fd03ceace51..cba4208a89f 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -4083,7 +4083,13 @@ gfc_match_rvalue (gfc_expr **result)
NULL. */
if (gfc_peek_ascii_char() == '(')
type_spec_list = true;
-
+ if (!actual_arglist && !type_spec_list)
+ {
+ gfc_error_now ("F2023 R755: The empty type specification at %C "
+ "is not allowed");
+ m = MATCH_ERROR;
+ break;
+ }
/* Generate this instance using the type parameters from the
first argument list and return the parameter list in
ctr_arglist. */
diff --git a/gcc/testsuite/gfortran.dg/pdt_17.f03 b/gcc/testsuite/gfortran.dg/pdt_17.f03
index d03e2d139a0..eab9ee9b54e 100644
--- a/gcc/testsuite/gfortran.dg/pdt_17.f03
+++ b/gcc/testsuite/gfortran.dg/pdt_17.f03
@@ -6,6 +6,6 @@
!
program p
type t(a) ! { dg-error "does not have a component" }
- integer(kind=t()) :: x ! { dg-error "Expected initialization expression" }
+ integer(kind=t()) :: x ! { dg-error "empty type specification" }
end type
end
diff --git a/gcc/testsuite/gfortran.dg/pdt_57.f03 b/gcc/testsuite/gfortran.dg/pdt_57.f03
new file mode 100644
index 00000000000..457ec794484
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_57.f03
@@ -0,0 +1,47 @@
+! { dg-do compile }
+!
+! Test the fix for pr95543. The variable declaration in each subroutine used to ICE
+! because the substitution of a in the default initializers of b was not being done.
+!
+! Contributed by Gerhard Steinmetz <[email protected]>
+!
+program p
+ call foo1
+ call foo2
+ call foo3
+ call foo4
+contains
+ subroutine foo1
+ type t(a, b)
+ integer, kind :: a = 4
+ integer, kind :: b = a + 4
+ end type
+ type(t()) :: z ! { dg-error "empty type specification" }
+ print *, z%b
+ end
+ subroutine foo2
+ type t(a, b)
+ integer, kind :: a = 1
+ integer, kind :: b = a
+ end type
+ type(t) :: z
+ print *, z%b
+ end
+ subroutine foo3
+ type t(a, b)
+ integer, kind :: a = 1
+ integer, kind :: b = a
+ end type
+ type(t(2)) :: z
+ print *, z%b
+ end
+ subroutine foo4
+ type t(a, b)
+ integer, kind :: a = 4
+ integer, kind :: b = a + 4
+ end type
+ type(t(b = 6)) :: z
+ print *, z%b
+ end
+end
+
diff --git a/gcc/testsuite/gfortran.dg/pdt_58.f03 b/gcc/testsuite/gfortran.dg/pdt_58.f03
new file mode 100644
index 00000000000..cf26e8a03bf
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_58.f03
@@ -0,0 +1,14 @@
+! { dg-do compile }
+!
+! Test fix for PR103748.
+!
+! Contributed by Bastiaan Braams <[email protected]>
+!
+program test
+ implicit none
+ type f_type
+ integer, allocatable :: x(:)
+ end type f_type
+ type (f_type(n=9)) :: f ! { dg-error "is not parameterized" }
+ stop
+end program test
