2 ! Test of an issue found in the investigation of PR112407
3 ! Contributed by Tomas Trnka <trnka@scm.com>
9 procedure(),pointer,nopass
:: op
19 generic
:: new
=> new_t
, bar
20 generic
, public
:: assignment(=) => add_t
24 integer :: i
= 0, finals
= 0
27 recursive subroutine new_t (arg1
, arg2
)
28 class(t
), intent(out
) :: arg1
29 type(t
), intent(in
) :: arg2
32 print "(a,2i4)", "new_t", arg1
%i
, arg2
%i
35 ! According to F2018(8.5.10), arg1 should be undefined on invocation, unless
36 ! any sub-components are default initialised. gfc used to set arg1%i = 0.
37 if (arg1
%i
.ne
. arg2
%i
) then
44 class(t
), intent(out
) :: arg
45 call arg
%new(t(42, s(new_t
)))
48 subroutine add_t (arg1
, arg2
)
49 class(t
), intent(out
) :: arg1
50 type(t
), intent(in
) :: arg2
54 impure elemental
subroutine final_t (arg1
)
55 type(t
), intent(in
) :: arg1
61 class(t
), allocatable
:: x
64 call x
%new() ! gfortran used to output 10*'new_t'
65 print "(3i4)", x
%i
, i
, finals
! -||- 0 10 11
67 ! The other brands output 2*'new_t' + 42 2 3 and now so does gfc :-)
68 if (x
%i
.ne
. 42) stop 1
70 if (finals
.ne
. 3) stop 3