From 356d1ab6ddb58559d3641f169f44fd24f7cb00d1 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 21 Feb 2022 22:49:05 +0100
Subject: [PATCH] Fortran: skip compile-time shape check if constructor shape
is not known
gcc/fortran/ChangeLog:
PR fortran/104619
* resolve.cc (resolve_structure_cons): Skip shape check if shape
of constructor cannot be determined at compile time.
gcc/testsuite/ChangeLog:
PR fortran/104619
* gfortran.dg/derived_constructor_comps_7.f90: New test.
---
gcc/fortran/resolve.cc | 2 ++
.../derived_constructor_comps_7.f90 | 28 +++++++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/derived_constructor_comps_7.f90
@@ -1472,6 +1472,8 @@ resolve_structure_cons (gfc_expr *expr, int init)
t = false;
break;
};
+ if (cons->expr->shape == NULL)
+ continue;
mpz_set_ui (len, 1);
mpz_add (len, len, comp->as->upper[n]->value.integer);
mpz_sub (len, len, comp->as->lower[n]->value.integer);
new file mode 100644
@@ -0,0 +1,28 @@
+! { dg-do run }
+! PR fortran/104619
+
+module m
+ implicit none
+ type :: item
+ real :: x
+ end type item
+ type :: container
+ type(item) :: items(3)
+ end type container
+end module
+
+program p
+ use m
+ implicit none
+ type(item), allocatable :: items(:)
+ type(container) :: c
+ integer :: i, n
+ items = [item(3.0), item(4.0), item(5.0)]
+ c = container(items=[(items(i), i = 1, size(items))])
+ if (any (c%items% x /= items% x)) stop 1
+ n = size (items)
+ c = container(items=[(items(i), i = 1, n)])
+ if (any (c%items% x /= items% x)) stop 2
+ c = container(items=[(items(i), i = 1, 3)])
+ if (any (c%items% x /= items% x)) stop 3
+end program
--
2.34.1