1! { dg-do compile }
2! { dg-options "-std=f2003" }
3
4! PR fortran/44044
5! Definability check for select type to expression.
6! This is "bonus feature #2" from comment #3 of the PR.
7
8! Contributed by Janus Weil, janus@gcc.gnu.org.
9
10implicit none
11
12type :: t1
13  integer :: i
14end type
15
16type, extends(t1) :: t2
17end type
18
19type(t1),target :: x1
20type(t2),target :: x2
21
22select type ( y => fun(1) )
23type is (t1)
24  y%i = 1 ! { dg-error "variable definition context" }
25type is (t2)
26  y%i = 2 ! { dg-error "variable definition context" }
27end select
28
29contains
30
31  function fun(i)
32    class(t1),pointer :: fun
33    integer :: i
34    if (i>0) then
35      fun => x1
36    else if (i<0) then
37      fun => x2
38    else
39      fun => NULL()
40    end if
41  end function
42
43end
44
45