aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/defined_assignment_1.f90
blob: da06f26d1910ce159ff2d86caba41787e473191e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
! { dg-do run }
! Test the fix for PR46897.
!
! Contributed by Rouson Damian <rouson@sandia.gov>
!
module m0
  implicit none
  type component
    integer :: i = 0
  contains
    procedure :: assign0
    generic :: assignment(=)=>assign0
  end type
  type parent
    type(component) :: foo
  end type
  type, extends(parent) :: child
    integer :: j
  end type
contains
  subroutine assign0(lhs,rhs)
    class(component), intent(out) :: lhs
    class(component), intent(in) :: rhs
    lhs%i = 20
  end subroutine 
  type(child) function new_child()
  end function
end module 

module m1
  implicit none
  type component1
    integer :: i = 1
  contains
    procedure :: assign1
    generic :: assignment(=)=>assign1
  end type
  type t
    type(component1) :: foo
  end type
contains
  subroutine assign1(lhs,rhs)
    class(component1), intent(out) :: lhs
    class(component1), intent(in) :: rhs
    lhs%i = 21
  end subroutine
end module

module m2
  implicit none
  type component2
    integer :: i = 2
  end type
  interface assignment(=)
    module procedure assign2
  end interface
  type t2
    type(component2) :: foo
  end type
contains
  subroutine assign2(lhs,rhs)
    type(component2), intent(out) :: lhs
    type(component2), intent(in) :: rhs
    lhs%i = 22
  end subroutine
end module 

program main
  use m0
  use m1
  use m2
  implicit none
  type(child) :: infant0
  type(t) :: infant1, newchild1
  type(t2) :: infant2, newchild2

! Test the reported problem.
  infant0 = new_child()
  if (infant0%parent%foo%i .ne. 20) call abort

! Test the case of comment #1 of the PR.
  infant1 = newchild1
  if (infant1%foo%i .ne. 21) call abort

! Test the case of comment #2 of the PR.
  infant2 = newchild2
  if (infant2%foo%i .ne. 2) call abort
end