c: Fix up pointer types to may_alias structures [PR114493]
[official-gcc.git] / gcc / testsuite / gfortran.dg / select_type_12.f03
blobeb942d1e13b6bec2bd6e5f761e489596aa60faa7
1 ! { dg-do compile }
3 ! PR 44044: [OOP] SELECT TYPE with class-valued function
5 ! Contributed by Janus Weil <janus@gcc.gnu.org>
7 implicit none
9 type :: t1
10   integer :: i
11 end type
13 type, extends(t1) :: t2
14 end type
16 type(t1),target :: x1
17 type(t2),target :: x2
19 select type ( y => fun(1) )
20 type is (t1)
21   print *,"t1"
22 type is (t2)
23   print *,"t2"
24 class default
25   print *,"default"
26 end select
28 select type ( y => fun(-1) )
29 type is (t1)
30   print *,"t1"
31 type is (t2)
32   print *,"t2"
33 class default
34   print *,"default"
35 end select
37 contains
39   function fun(i)
40     class(t1),pointer :: fun
41     integer :: i
42     if (i>0) then
43       fun => x1
44     else if (i<0) then
45       fun => x2
46     else
47       fun => NULL()
48     end if
49   end function
51 end