File: allocate_with_source_26.f90

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (91 lines) | stat: -rw-r--r-- 2,272 bytes parent folder | download | duplicates (2)
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
91
! { dg-do run }
!
! Ensure that the lower bound starts with the correct
! value
!
! PR fortran/87580
! PR fortran/67125
!
! Contributed by Antony Lewis and mrestelli
!
program p
 implicit none
 integer, allocatable :: a(:), b(:), c(:), d(:), e(:)
 type t
   integer :: i
 end type t
 class(t), allocatable :: p1(:), p2(:), p3(:), p4(:)
 integer :: vec(6)

 vec = [1,2,3,4,5,6]

 allocate(a, source=f(3))
 allocate(b, source=g(3))
 allocate(c, source=h(3))
 allocate(d, source=[1,2,3,4,5])
 allocate(e, source=vec)

 allocate(p1(3:4))
 p1(:)%i = [43,56]
 allocate(p2, source=p1)
 call do_allocate(p1, size(p1))
 allocate(p4, source=poly_init())

 if (lbound(p1, 1) /= 3 .or. ubound(p1, 1) /= 4 &
     .or. lbound(p2, 1) /= 3 .or. ubound(p2, 1) /= 4 &
     .or. lbound(p3, 1) /= 1 .or. ubound(p3, 1) /= 2 &
     .or. lbound(p4, 1) /= 1 .or. ubound(p4, 1) /= 2 &
     .or. p1(3)%i /= 43 .or. p1(4)%i /= 56 &
     .or. p2(3)%i /= 43 .or. p2(4)%i /= 56 &
     .or. p3(1)%i /= 43 .or. p3(2)%i /= 56 &
     .or. p4(1)%i /= 11 .or. p4(2)%i /= 12) then
   call abort()
 endif

 !write(*,*) lbound(a,1), ubound(a,1) ! prints 1 3
 !write(*,*) lbound(b,1), ubound(b,1) ! prints 1 3
 !write(*,*) lbound(c,1), ubound(c,1) ! prints 1 3
 !write(*,*) lbound(d,1), ubound(d,1) ! prints 1 5
 !write(*,*) lbound(e,1), ubound(e,1) ! prints 1 6

 if (lbound(a,1) /= 1 .or. ubound(a,1) /= 3 &
     .or. lbound(b,1) /= 1 .or. ubound(b,1) /= 3 &
     .or. lbound(c,1) /= 1 .or. ubound(c,1) /= 3 & 
     .or. lbound(d,1) /= 1 .or. ubound(d,1) /= 5 &
     .or. lbound(e,1) /= 1 .or. ubound(e,1) /= 6) then
   call abort()
 endif
   
contains

 subroutine do_allocate(x, n)
   integer, value :: n
   class(t), intent(in) :: x(n)
   allocate(p3, source=x)
 end subroutine

 function poly_init()
   class(t), allocatable :: poly_init(:)
   allocate(poly_init(7:8))
   poly_init = [t :: t(11), t(12)]
 end function poly_init

 pure function f(i)
  integer, intent(in) :: i
  integer :: f(i)
   f = 2*i
 end function f

 pure function g(i) result(r)
  integer, value, intent(in) :: i
  integer, allocatable :: r(:)
  r = [1,2,3]
 end function g

 pure function h(i) result(r)
  integer, value, intent(in) :: i
  integer, allocatable :: r(:)
  allocate(r(3:5))
  r = [1,2,3]
 end function h
end program p