PR 61281: Memory corruption on assigning a polymorphic variable to a non-polymorphic one
Damian Rouson
rouson@stanford.edu
Thu May 22 04:17:00 GMT 2014
Gfortran developers,
I just submitted the following as PR 61281:
The code below demonstrates a bug isolated from code from my collaborator Rob Rosenberg of the Naval Research Laboratory. The code exhibits an apparent memory corruption issue with gfortran 4.9 dated 20140416. Gfortran 4.8.2 rejects the code with the message below.
Damian
$ cat rob.f90
type employees
character(3) :: name="rob"
end type
type companies
type(employees) :: list
end type
type(companies) :: nrl
print *,nrl%list
call map
print *,nrl%list
contains
type (employees) function give_raise(e)
class(employees) :: e ! Switch to "type" to hide bug
give_raise=e
end function
subroutine map()
nrl%list=give_raise(nrl%list)
end subroutine
end
$ gfortran rob.f90
$ ./a.out
rob
8??
$ gfortran --version
GNU Fortran (MacPorts gcc49 4.9-20140416_0) 4.9.0 20140416 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
$ sudo port select --set gcc mp-gcc48
Selecting 'mp-gcc48' for 'gcc' succeeded. 'mp-gcc48' is now active.
$ gfortran rob.f90
rob.f90:14.15:
give_raise=e
1
Error: Can't convert CLASS(employees) to TYPE(employees) at (1)
localhost:Desktop rouson$ gfortran --version
GNU Fortran (MacPorts gcc48 4.8.2_0) 4.8.2
More information about the Fortran
mailing list