From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24132 invoked by alias); 16 Apr 2008 20:05:30 -0000 Received: (qmail 23952 invoked by uid 48); 16 Apr 2008 20:04:45 -0000 Date: Wed, 16 Apr 2008 20:05:00 -0000 Subject: [Bug fortran/35959] New: Recursive function with allocatable array X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "michael dot baudin at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-04/txt/msg01171.txt.bz2 Problem with gfortran while developing a recursive function which allocates an array stored in a derived-type. This is the sample test : module testmod #define _DYNAMIC_TYPE allocatable !#define _DYNAMIC_TYPE pointer type, public :: t_type integer, dimension(:), _DYNAMIC_TYPE :: chars end type t_type integer, save :: callnb = 0 contains recursive function recursivefunc ( this ) result ( match ) type(t_type), intent(in) :: this type(t_type) :: subpattern logical :: thisalloc integer :: thislength logical :: match write ( * , * ) "recursivefunc [" , callnb , "]" thislength = size ( this % chars ) write ( * , * ) "length :", thislength callnb = callnb + 1 thisalloc = allocated ( this % chars ) ! thisalloc = associated ( this % chars ) if ( .NOT. thisalloc ) then write ( 6 , * ) "STOP with error !" stop endif if ( thislength == 0 ) then match = .true. return endif allocate ( subpattern % chars ( thislength - 1 ) ) match = recursivefunc ( subpattern ) end function recursivefunc end module testmod program testprog use testmod implicit none type(t_type) :: this logical :: match allocate ( this % chars ( 10 )) match = recursivefunc ( this ) print * , "match :", match end program testprog Compile it with : gfortran -x f95-cpp-input testZeroSizeRecursive2.f90 -o testZeroSizeRecursive2.exe (flibs-workbench) 60 % testZeroSizeRecursive2.exe recursivefunc [ 0 ] length : 10 recursivefunc [ 1 ] length : 9 STOP with error ! This is because the allocated statement return .false., even if the array is really allocated. Trying the "pointer" version by modifying the #define preprocessing statement and the "allocated" to associated" make the problem disappear : recursivefunc [ 0 ] length : 10 recursivefunc [ 1 ] length : 9 recursivefunc [ 2 ] length : 8 recursivefunc [ 3 ] length : 7 recursivefunc [ 4 ] length : 6 recursivefunc [ 5 ] length : 5 recursivefunc [ 6 ] length : 4 recursivefunc [ 7 ] length : 3 recursivefunc [ 8 ] length : 2 recursivefunc [ 9 ] length : 1 recursivefunc [ 10 ] length : 0 match : T This is the version of gfortran I currently use ( I downloaded it today and I think that it is up-todate ) : (flibs-workbench) 61 % gfortran -v Using built-in specs. Target: i586-pc-mingw32 Configured with: ../trunk/configure --prefix=/mingw --enable-languages=c,fortran --with-gmp=/home/FX/local --with-ld=/mingw/bin/ld --with-as=/mingw/bin/as --disable-werror --enable-bootstrap --enable-threads --disable-nls --build=i586-pc-mingw32 --enable-libgomp --disable-shared Thread model: win32 gcc version 4.4.0 20080312 (experimental) [trunk revision 133139] (GCC) Regards, Michaƫl Baudin -- Summary: Recursive function with allocatable array Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: michael dot baudin at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35959