In the following program, env%n should be equal to zero when entering the
routine "titi" but one gets the output :

  10 0
   5 10

instead of

  10 0
   5 0

as if the local variable "env" was declared "save" within "titi". Notice that
the bug disappears if the allocatable array "a" is deleted in the definition of
"env_type" : so the presence of an allocatable element within a derived type
seems to be related to that bug.

MODULE m

  TYPE env_type
    INTEGER :: n=0
    INTEGER,ALLOCATABLE :: a(:)
  END TYPE

  CONTAINS

  RECURSIVE SUBROUTINE titi(n)

    INTERFACE
      RECURSIVE SUBROUTINE tata()
      END SUBROUTINE
    END INTERFACE

    TYPE(env_type) :: env
    WRITE(*,*) n,env%n
    env%n=n
    IF(n == 5) STOP
    CALL tata()

  END SUBROUTINE

END MODULE

RECURSIVE SUBROUTINE tata
  USE m
  CALL titi(5)
END SUBROUTINE

PROGRAM test
  USE m
  INTERFACE
    RECURSIVE SUBROUTINE tata()
    END SUBROUTINE
  END INTERFACE
  CALL titi(10)
END PROGRAM


-- 
           Summary: wrong initialization of local variable in a recursive
                    subroutine
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: francois dot jacq at irsn dot fr
  GCC host triplet: windows xp i386
GCC target triplet: gcc 4.3.0 20080305 (alpha-testing) mingw-20080502


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

Reply via email to