2 ! PR51634 - Handle allocatable components correctly in expressions
3 ! involving typebound operators. From comment 2 of PR but using
6 ! Reported by Tobias Burnus <burnus@gcc.gnu.org>
8 module soop_stars_class
11 real, dimension(:), allocatable :: position,velocity
16 generic :: operator(+) => total
17 generic :: operator(*) => mult
18 generic :: assignment(=) => assign
21 function mult(lhs,rhs)
22 class(soop_stars) ,intent(in) :: lhs
23 real ,intent(in) :: rhs
24 class(soop_stars), allocatable :: mult
25 type(soop_stars) :: tmp
26 tmp = soop_stars (lhs%position*rhs, lhs%velocity*rhs)
27 allocate (mult, source = tmp)
30 function total(lhs,rhs)
31 class(soop_stars) ,intent(in) :: lhs,rhs
32 class(soop_stars), allocatable :: total
33 type(soop_stars) :: tmp
34 tmp = soop_stars (lhs%position + rhs%position, &
35 lhs%velocity + rhs%velocity)
36 allocate (total, source = tmp)
39 subroutine assign(lhs,rhs)
40 class(soop_stars), intent(in) :: rhs
41 class(soop_stars), intent(out) :: lhs
42 lhs%position = rhs%position
43 lhs%velocity = rhs%velocity
48 use soop_stars_class ,only : soop_stars
50 class(soop_stars), allocatable :: fireworks
52 allocate (fireworks, source = soop_stars ([1,2,3], [4,5,6]))
54 fireworks = fireworks + fireworks*dt
55 if (any (fireworks%position .ne. [6, 12, 18])) STOP 1
56 if (any (fireworks%velocity .ne. [24, 30, 36])) STOP 2