File: dynamic_dispatch_7.f03

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (59 lines) | stat: -rw-r--r-- 1,168 bytes parent folder | download | duplicates (3)
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
! { dg-do run }
! Test the fix for PR43291, which was a regression that caused
! incorrect type mismatch errors at line 46. In the course of
! fixing the PR, it was noted that the dynamic dispatch of the
! final typebound call was not occurring - hence the dg-do run.
!
! Contributed by Janus Weil <janus@gcc.gnu.org>
!
module m1
  type :: t1
  contains
    procedure :: sizeof
  end type
contains
  integer function sizeof(a)
    class(t1) :: a
    sizeof = 1
  end function sizeof
end module
	
module m2
  use m1
  type, extends(t1) :: t2
  contains
    procedure :: sizeof => sizeof2
  end type
contains
  integer function sizeof2(a)
    class(t2) :: a
    sizeof2 = 2
  end function
end module

module m3
  use m2
  type :: t3
  class(t1), pointer :: a
  contains
    procedure :: sizeof => sizeof3
  end type
contains
  integer function sizeof3(a)
    class(t3) :: a
    sizeof3 = a%a%sizeof()
  end function
end module

  use m1
  use m2
  use m3
  type(t1), target :: x
  type(t2), target :: y
  type(t3) :: z
  z%a => x
  if ((z%sizeof() .ne. 1) .or. (z%a%sizeof() .ne. 1)) STOP 1
  z%a => y
  if ((z%sizeof() .ne. 2) .or. (z%a%sizeof() .ne. 2)) STOP 2
end