diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 0e12730..60bfb31 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -5155,18 +5155,25 @@ select_type_set_tmp (gfc_typespec *ts) /* Copy across the array spec to the selector, taking care as to whether or not it is a class object or not. */ if (select_type_stack->selector->ts.type == BT_CLASS && - CLASS_DATA (select_type_stack->selector)->attr.dimension) + (CLASS_DATA (select_type_stack->selector)->attr.dimension + || CLASS_DATA (select_type_stack->selector)->attr.codimension)) { if (ts->type == BT_CLASS) { - CLASS_DATA (tmp->n.sym)->attr.dimension = 1; + CLASS_DATA (tmp->n.sym)->attr.dimension + = CLASS_DATA (select_type_stack->selector)->attr.dimension; + CLASS_DATA (tmp->n.sym)->attr.codimension + = CLASS_DATA (select_type_stack->selector)->attr.codimension; CLASS_DATA (tmp->n.sym)->as = gfc_get_array_spec (); CLASS_DATA (tmp->n.sym)->as = CLASS_DATA (select_type_stack->selector)->as; } else { - tmp->n.sym->attr.dimension = 1; + tmp->n.sym->attr.dimension + = CLASS_DATA (select_type_stack->selector)->attr.dimension; + tmp->n.sym->attr.codimension + = CLASS_DATA (select_type_stack->selector)->attr.codimension; tmp->n.sym->as = gfc_get_array_spec (); tmp->n.sym->as = CLASS_DATA (select_type_stack->selector)->as; } diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index b4a9d1c..bb96f7c 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -12417,6 +12417,7 @@ resolve_symbol (gfc_symbol *sym) /* F2008, C526. The function-result case was handled above. */ if (sym->attr.codimension && !(sym->attr.allocatable || sym->attr.dummy || sym->attr.save + || sym->attr.select_type_temporary || sym->ns->save_all || sym->ns->proc_name->attr.flavor == FL_MODULE || sym->ns->proc_name->attr.is_main_program @@ -12428,7 +12429,8 @@ resolve_symbol (gfc_symbol *sym) } /* F2008, C528. */ /* FIXME: sym->as check due to PR 43412. */ else if (sym->attr.codimension && !sym->attr.allocatable - && sym->as && sym->as->cotype == AS_DEFERRED) + && sym->as && sym->as->cotype == AS_DEFERRED + && !sym->attr.select_type_temporary) { gfc_error ("Coarray variable '%s' at %L shall not have codimensions with " "deferred shape", sym->name, &sym->declared_at); --- /dev/null 2011-12-13 13:39:04.395699646 +0100 +++ gcc/gcc/testsuite/gfortran.dg/coarray_select_type_1.f90 2011-12-13 23:40:58.000000000 +0100 @@ -0,0 +1,41 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! +! PR fortran/46371 +! +! +module m + type :: foo + integer :: i = 0 + end type +end module m +program p + use m + implicit none + class(foo), allocatable :: o_foo[:] + class(foo), allocatable :: o_bar(:)[:] + integer :: j + + allocate(foo :: o_foo[*]) + allocate(foo :: o_bar(5)[*]) + + select type(o_bar) + type is(foo) + j = o_bar(1)[1]%i + end select + + select type(a => o_bar) + type is(foo) + j = a(1)[1]%i + end select + + select type(o_foo) + type is(foo) + j = o_foo[1]%i + end select + + select type(a => o_foo) + type is(foo) + j = a[1]%i + end select +end program p