http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516
--- Comment #4 from janus at gcc dot gnu.org 2011-02-06 12:28:42 UTC --- We also need to adjust gfc_get_derived_type, to avoid running into an infinite loop. Updated patch: Index: gcc/testsuite/gfortran.dg/class_2.f03 =================================================================== --- gcc/testsuite/gfortran.dg/class_2.f03 (revision 169853) +++ gcc/testsuite/gfortran.dg/class_2.f03 (working copy) @@ -36,7 +36,7 @@ end interface type t6 integer :: i - class(t6), allocatable :: foo ! { dg-error "must have the POINTER attribute" } + class(t6) :: foo ! { dg-error "must be POINTER or ALLOCATABLE" } end type t6 Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 169853) +++ gcc/fortran/decl.c (working copy) @@ -1515,14 +1515,20 @@ build_struct (const char *name, gfc_charlen *cl, g gfc_component *c; gfc_try t = SUCCESS; - /* F03:C438/C439. If the current symbol is of the same derived type that we're - constructing, it must have the pointer attribute. */ + /* F03:C438/C439, F08:C440. If the current symbol is of the same derived type + that we're constructing, it must be POINTER or ALLOCATABLE. */ if ((current_ts.type == BT_DERIVED || current_ts.type == BT_CLASS) && current_ts.u.derived == gfc_current_block () && current_attr.pointer == 0) { - gfc_error ("Component at %C must have the POINTER attribute"); - return FAILURE; + if (gfc_notify_std (GFC_STD_F2008, "Component at %C must have the " + "POINTER attribute") == FAILURE) + return FAILURE; + else if (current_attr.allocatable == 0) + { + gfc_error ("Component at %C must be POINTER or ALLOCATABLE"); + return FAILURE; + } } if (gfc_current_block ()->attr.pointer && (*as)->rank != 0) Index: gcc/fortran/trans-types.c =================================================================== --- gcc/fortran/trans-types.c (revision 169853) +++ gcc/fortran/trans-types.c (working copy) @@ -2096,14 +2096,14 @@ gfc_get_derived_type (gfc_symbol * derived) /* Go through the derived type components, building them as necessary. The reason for doing this now is that it is possible to recurse back to this derived type through a - pointer component (PR24092). If this happens, the fields + pointer or allocatable component. If this happens, the fields will be built and so we can return the type. */ for (c = derived->components; c; c = c->next) { if (c->ts.type != BT_DERIVED && c->ts.type != BT_CLASS) continue; - if ((!c->attr.pointer && !c->attr.proc_pointer) + if ((!c->attr.pointer && !c->attr.proc_pointer && !c->attr.allocatable) || c->ts.u.derived->backend_decl == NULL) c->ts.u.derived->backend_decl = gfc_get_derived_type (c->ts.u.derived);