Debian Codegraph @

gcc/testsuite/gfortran.dg/pr119948.f90

raw
1 ! { dg-do run }
2 !
3 ! Test the fix for PR119948, which used to fail as indicated below with:
4 ! (1) "Error: Bad allocate-object at (1) for a PURE procedure"
5 ! (2) "Error: ‘construct_test2 at (1) is not a variable"
6 !
7 ! Contributed by Damian Rouson <[email protected]>
8 !
9 module test_m
10 implicit none
11
12 type test_t
13 integer, allocatable :: i
14 end type
15
16 interface
17 pure module function construct_test(arg) result(test)
18 implicit none
19 type(test_t) :: test
20 type(test_t), intent(in) :: arg
21 end function
22
23 pure module function construct_test2(arg)
24 implicit none
25 type(test_t) construct_test2
26 type(test_t), intent(in) :: arg
27 end function
28
29 pure module function construct_test_3(arg) result(test)
30 implicit none
31 type(test_t) :: test
32 type(test_t), intent(in) :: arg
33 end function
34
35 pure module function construct_test_4(arg)
36 implicit none
37 type(test_t) :: construct_test_4
38 type(test_t), intent(in) :: arg
39 end function
40 end interface
41
42 contains
43 module procedure construct_test
44 allocate(test%i, source = arg%i) ! Fail #1
45 end procedure
46
47 module procedure construct_test2
48 allocate(construct_test2%i, source = arg%i) ! Fail #2
49 end procedure
50 end module
51
52 submodule (test_m)test_s
53 contains
54 module procedure construct_test_3
55 allocate(test%i, source = arg%i) ! This was OK.
56 end procedure
57
58 module procedure construct_test_4
59 allocate(construct_test_4%i, source = arg%i) ! This was OK.
60 end procedure
61 end submodule
62
63 use test_m
64 type(test_t) :: res, dummy
65 !
66 dummy%i = int (rand () * 1e6)
67 res = construct_test (dummy)
68 if (res%i /= dummy%i) stop 1
69 !
70 dummy%i = int (rand () * 1e6)
71 res = construct_test2 (dummy)
72 if (res%i /= dummy%i) stop 2
73 !
74 dummy%i = int (rand () * 1e6)
75 res = construct_test_3 (dummy)
76 if (res%i /= dummy%i) stop 3
77
78 dummy%i = int (rand () * 1e6)
79 res = construct_test_4 (dummy)
80 if (res%i /= dummy%i) stop 4
81
82 deallocate (res%i, dummy%i)
83 end