This simple patch kindly provided by Marco solves the problem. Regression tested on x86_64-Linux, Test case provided also.
OK to commit to trunk? Jerry 2016-07-14 Jerry DeLisle <jvdeli...@gcc.gnu.org> Marco Restelli <mreste...@gmail.com> PR fortran/62125 * symbol.c (select_type_insert_tmp): Recursively call self to take care of nested select type. diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c index 0ee7dec..c967f25 100644 --- a/gcc/fortran/symbol.c +++ b/gcc/fortran/symbol.c @@ -2930,7 +2930,11 @@ select_type_insert_tmp (gfc_symtree **st) gfc_select_type_stack *stack = select_type_stack; for (; stack; stack = stack->prev) if ((*st)->n.sym == stack->selector && stack->tmp) - *st = stack->tmp; + { + *st = stack->tmp; + select_type_insert_tmp (st); + return; + } }
! { dg-do run } ! PR62125 Nested select type not accepted (rejects valid) module m implicit none type, abstract :: t1 logical :: l end type t1 type, extends(t1), abstract :: t2 integer :: i end type t2 type, extends(t2) :: t3 real :: x end type t3 contains subroutine s(u) class(t1), intent(in) :: u if(.not.u%l) call abort() select type(u); class is(t2) if(u%i.ne.2) call abort() select type(u); class is(t3) if(u%x.ne.3.5) call abort() end select end select end subroutine s end module m program p use m implicit none type(t3) :: var = t3( l=.true. , i=2 , x=3.5 ) call s(var) end program p