2 ! { dg-options "-fno-tree-vrp" }
4 ! Contributed by Federico Perini.
7 use iso_fortran_env
, only
: real64
14 real(real64
), allocatable
:: x(:)
18 procedure
:: init
=> t_init
19 procedure
:: destroy
=> t_destroy
20 procedure
:: print => t_print
22 procedure
, private
, pass(this
) :: x_minus_t
23 generic
:: operator(-) => x_minus_t
30 elemental
subroutine t_destroy(this
)
31 class(t
), intent(inout
) :: this
33 if (allocated(this
%x
)) deallocate(this
%x
)
34 end subroutine t_destroy
36 subroutine t_init(this
,n
)
37 class(t
), intent(out
) :: this
38 integer, intent(in
) :: n
44 type(t
) function x_minus_t(x
,this
) result(xmt
)
45 real(real64
), intent(in
) :: x
46 class(t
), intent(in
) :: this
48 xmt
%x(:) = x
-this
%x(:)
49 end function x_minus_t
51 subroutine t_print(this
,msg
)
52 class(t
), intent(in
) :: this
53 character(*), intent(in
) :: msg
57 print "('type(t) object <',a,'>, size=',i0)", msg
,this
%n
59 print "(' x(',i0,') =',1pe12.5)",i
,this
%x(i
)
62 end subroutine t_print
67 program test_overloaded
73 ! Error with result (5)
74 call t1
%init(5); t1
%x(:) = 1.0_real64
; r1
= 3.0_real64
- t1
75 if (any(r1
%x
/= 2.0)) stop 1
79 call t1
%init(6); t1
%x(:) = 1.0_real64
; r1
= 3.0_real64
- t1
80 if (any(r1
%x
/= 2.0)) stop 2
84 end program test_overloaded