3 ! Checks the fix for PR69556 in which using implicit function results
4 ! in SELECT TYPE caused all sorts of problems, especially in the form
5 ! in 'return_pointer1' with "associate_name => selector". The original
6 ! PR is encapsulated in 'return_pointer'. Explicit results, such as in
7 ! 'return_pointer2' always worked.
9 ! Contributed by James Greenhalgh <jgreenhalgh@gcc.gnu.org>
12 class(*), pointer :: ptr(:)
13 character(40) :: buffer1, buffer2
14 real :: cst1(2) = [1.0, 2.0]
15 real :: cst2(2) = [3.0, 4.0]
16 real :: cst3(2) = [5.0, 6.0]
18 write (buffer1, *) cst1
19 if (.not.associated(return_pointer1(cst1))) STOP 1
20 if (trim (buffer1) .ne. trim (buffer2)) STOP 2
23 if (any (ptr .ne. cst2)) STOP 3
27 write (buffer1, *) cst2
28 if (.not.associated(return_pointer(cst2))) STOP 4
29 if (trim (buffer1) .ne. trim (buffer2)) STOP 5
32 if (any (ptr .ne. cst3)) STOP 6
36 write (buffer1, *) cst1
37 if (.not.associated(return_pointer2(cst1))) STOP 7
38 if (trim (buffer1) .ne. trim (buffer2)) STOP 8
41 if (any (ptr .ne. cst2)) STOP 9
47 function return_pointer2(arg) result (res) ! Explicit result always worked.
48 class(*), pointer :: res(:)
49 real, intent(inout) :: arg(:)
50 allocate (res, source = arg)
51 ptr => res ! Check association and cleanup
52 select type (z => res)
54 write (buffer2, *) z ! Check associate expression is OK.
55 z = cst2 ! Check associate is OK for lvalue.
59 function return_pointer1(arg)
60 class(*), pointer :: return_pointer1(:)
61 real, intent(inout) :: arg(:)
62 allocate (return_pointer1, source = arg)
63 ptr => return_pointer1
64 select type (z => return_pointer1) ! This caused a segfault in compilation.
71 function return_pointer(arg) ! The form in the PR.
72 class(*), pointer :: return_pointer(:)
73 real, intent(inout) :: arg(:)
74 allocate (return_pointer, source = cst2)
76 select type (return_pointer)
77 type is (real(4)) ! Associate-name ‘__tmp_REAL_4’ at (1) is used as array
78 write (buffer2, *) return_pointer