Bug 86888

Summary: [F08] allocatable components of indirectly recursive type
Product: gcc Reporter: janus
Component: fortranAssignee: janus
Status: RESOLVED FIXED    
Severity: normal Keywords: rejects-valid
Priority: P3    
Version: 9.0   
Target Milestone: 9.0   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45516
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82036
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87172
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 39627    

Description janus 2018-08-08 11:31:59 UTC
Test case:


type :: s
   type(t), allocatable :: x
end type

type :: t
   type(s), allocatable :: y
end type

end


gfortran trunk rejects this with:

    type(t), allocatable :: x
                          1
Error: Derived type at (1) has not been previously defined and so cannot appear in a derived type definition


IIUC this is valid in F08:

C440 (R436) If neither the POINTER nor the ALLOCATABLE attribute is specified, the declaration-type-spec in the component-def-stmt shall specify an intrinsic type or a previously defined derived type.

ifort 18 accepts it happily.
Comment 1 janus 2018-08-08 11:52:16 UTC
Draft patch:

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 263395)
+++ gcc/fortran/decl.c	(working copy)
@@ -5864,8 +5864,7 @@ gfc_match_data_decl (void)
       if (current_attr.pointer && gfc_comp_struct (gfc_current_state ()))
 	goto ok;
 
-      if (current_attr.allocatable && gfc_current_state () == COMP_DERIVED
-	  && current_ts.u.derived == gfc_current_block ())
+      if (current_attr.allocatable && gfc_current_state () == COMP_DERIVED)
 	goto ok;
 
       gfc_find_symbol (current_ts.u.derived->name,



Shows only one regression in the testsuite:

FAIL: gfortran.dg/alloc_comp_basics_6.f90   -O   (test for errors, line 8)
Comment 2 janus 2018-08-22 17:10:32 UTC
Author: janus
Date: Wed Aug 22 17:10:00 2018
New Revision: 263782

URL: https://gcc.gnu.org/viewcvs?rev=263782&root=gcc&view=rev
Log:
fix PR 86888

2018-08-22  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/86888
	* decl.c (gfc_match_data_decl): Allow allocatable components of
	indirectly recursive type.
	* resolve.c (resolve_component): Remove two errors messages ...
	(resolve_fl_derived): ... and replace them by a new one.

2018-08-22  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/86888
	* gfortran.dg/alloc_comp_basics_6.f90: Update an error message and add
	an additional case.
	* gfortran.dg/alloc_comp_basics_7.f90: New test case.
	* gfortran.dg/class_17.f03: Update error message.
	* gfortran.dg/class_55.f90: Ditto.
	* gfortran.dg/dtio_11.f90: Update error messages.
	* gfortran.dg/implicit_actual.f90: Add an error message.
	* gfortran.dg/typebound_proc_12.f90: Update error message.

Added:
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_basics_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_basics_6.f90
    trunk/gcc/testsuite/gfortran.dg/class_17.f03
    trunk/gcc/testsuite/gfortran.dg/class_55.f90
    trunk/gcc/testsuite/gfortran.dg/dtio_11.f90
    trunk/gcc/testsuite/gfortran.dg/implicit_actual.f90
    trunk/gcc/testsuite/gfortran.dg/typebound_proc_12.f90
Comment 3 janus 2018-08-22 17:31:53 UTC
Fixed on 9-trunk with r263782. Closing.