gfc_apply_init (&c->ts, &c->attr, c->initializer);
+ /* Convert a class, PDT component of a non-derived type to a specific instance
+ before gfc_build_class_symbol gets to work on it. */
+ if (c->ts.type == BT_CLASS
+ && !(gfc_current_block ()->attr.pdt_template
+ || gfc_current_block ()->attr.pdt_type)
+ && c->ts.u.derived->attr.pdt_template)
+ {
+ match m = gfc_get_pdt_instance (decl_type_param_list, &c->ts.u.derived, NULL);
+ if (m != MATCH_YES)
+ {
+ if (!gfc_error_check ())
+ gfc_error ("Parameterized component of a non-parameterized "
+ "derived type at %C could not be converted to a valid "
+ "instance");
+ return false;
+ }
+ }
+
/* Check array components. */
if (!c->attr.dimension)
goto scalar;
! { dg-do run }
+! { dg-options "-fdump-tree-original" }
!
! Test the fix for PR110012, which failed to compile with an ICE.
+! Later, it was found that mfe_disc_test was leaking memory because
+! the 'navier_stokes' component p was given the PDT template dynamic
+! type, rather than that of the correct instance. This is detected
+! by the added, final subroutine being called twice, rather than
+! once (PR121972).
!
! Contributed by Neil Carlson <neil.n.carlson@gmail.com>
!
use pde_class
type, extends(pde) :: navier_stokes
integer, allocatable :: data_(:)
+ contains
+ final :: finalIze_navier_stokes
end type
+ integer :: ctr = 0
contains
subroutine alloc_navier_stokes(p , n)
class(pde(:)), allocatable :: p
p%data_ = [(i, i = 1, p%npde)]
end select
end subroutine
+ impure elemental subroutine finalIze_navier_stokes (self)
+ type(navier_stokes), intent(inout) :: self
+ ctr = ctr + 1
+ end
end module
module mfe_disc_type
end module
program test
+ use navier_stokes_type
call navier_stokes_test
call mfe_disc_test
+ if (ctr /= 2) stop 3
contains
subroutine navier_stokes_test
- use navier_stokes_type
class (pde(:)), allocatable :: x
call alloc_navier_stokes (x, 4)
select type (x)
end subroutine
subroutine mfe_disc_test
- use navier_stokes_type
use mfe_disc_type
type (foo), allocatable :: x
allocate (x)
if (allocated (x) .and. allocated (x%p)) deallocate (x%p)
end subroutine
end program
+! { dg-final { scan-tree-dump-times "VIEW_CONVERT_EXPR" 0 "original" } }