A subroutine or function that calls itself recursively must be declared with
the RECURSIVE attribute.  gfortran should refuse to compile the subroutine
below and return an error indicating that the RECURSIVE attribute must be
specified.

>$ cat sub.f90 
SUBROUTINE SUB()
CALL SUB()
END SUBROUTINE
>$ gfortran -std=f95 -pedantic sub.f90 -c
>$ gfortran -c -v
Using built-in specs.
Target: powerpc-apple-darwin8.1.0
Configured with: ../gcc-4.1-20050611/configure --enable-threads=posix
--enable-languages=c++,f95
Thread model: posix
gcc version 4.1.0 20050611 (experimental)

For comparison, here is output from g95 and xlf90:
>$ g95 -std=f95 -pedantic sub.f90 -c
In file sub.f90:2

CALL SUB()
         1
Error: SUBROUTINE 'sub' at (1) must be RECURSIVE in order to call itself
>$ xlf90 -qsuffix=cpp=f90 -f95 sub.f90 -c
"sub.f90", line 2.6: 1513-126 (S) Recursive calls are only permitted when the
RECUR option is specified or the RECURSIVE keyword is specified.
** sub   === End of Compilation 1 ===
1501-511  Compilation failed for file sub.f90.


On a related note, the limitations on RECURSIVE subroutines and functions
should also be extended to any ENTRY statements within the subprogram.  For
example, the following code is also illegal but gfortran currently accepts it:

>$ cat sub2.f90 
SUBROUTINE SUB2()
ENTRY ENT2()
CALL ENT2()
END SUBROUTINE
>$ gfortran -std=f95 -pedantic sub2.f90 -c

For comparison, xlf has the following output:
>$ xlf90 -qsuffix=cpp=f90 -f95 sub2.f90 -c
"sub2.f90", line 3.6: 1513-126 (S) Recursive calls are only permitted when the
RECUR option is specified or the RECURSIVE keyword is specified.
** sub2   === End of Compilation 1 ===
1501-511  Compilation failed for file sub2.f90.


-- 
           Summary: gfortran compiles recursive subroutines declared without
                    the RECURSIVE attribute
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bdtaylo1 at uiuc dot edu
 GCC build triplet: powerpc-apple-darwin8.1.0
  GCC host triplet: powerpc-apple-darwin8.1.0
GCC target triplet: powerpc-apple-darwin8.1.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26551

Reply via email to