[Bug fortran/43945] New: [OOP] Derived type with GENERIC: resolved to the wrong specific TBP
burnus at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Fri Apr 30 09:25:00 GMT 2010
Another OOP problem found by Salvatore.
Jim Xia confirms that NAG f95 gives the correct result, cf.
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/e18d0434c46598e2
"The GENERIC is Fortran is designed as such that the invocation is resolved at
compile time to a specific binding. In your case, af2%do() and af2%get() both
are solved to call binding a2f%doit() and af2%getit(). These two calls are
equivalent to af2%doit() and af2%getit(). And based on the dynamic type of
af2, routines doit2() and getit2() are both called."
The following program shows (GCC trunk after fortran-dev merge):
FOO%DOIT base version
Getit value : 1
Expect result (as with NAG):
FOO2%DOIT derived version
Getit value : 3
This result is also obtained with gfortran if lines with "!!$" are uncommented
- which is also the result with NAG f95 5.2. (NAG v5.1 rejects the latter code
with a seemingly bogus "ambiguous specific type-bound procedures".)
! ------------------- testd15.f03----------------
module foo_mod
type foo
integer :: i
contains
procedure, pass(a) :: doit
procedure, pass(a) :: getit
generic, public :: do => doit
generic, public :: get => getit
end type foo
private doit,getit
contains
subroutine doit(a)
class(foo) :: a
a%i = 1
write(*,*) 'FOO%DOIT base version'
end subroutine doit
function getit(a) result(res)
class(foo) :: a
integer :: res
res = a%i
end function getit
end module foo_mod
module foo2_mod
use foo_mod
type, extends(foo) :: foo2
integer :: j
contains
procedure, pass(a) :: doit => doit2
procedure, pass(a) :: getit => getit2
!!$ generic, public :: do => doit
!!$ generic, public :: get => getit
end type foo2
private doit2, getit2
contains
subroutine doit2(a)
class(foo2) :: a
a%i = 2
a%j = 3
write(*,*) 'FOO2%DOIT derived version'
end subroutine doit2
function getit2(a) result(res)
class(foo2) :: a
integer :: res
res = a%j
end function getit2
end module foo2_mod
program testd15
use foo2_mod
type(foo2) :: af2
call af2%do()
write(*,*) 'Getit value : ', af2%get()
end program testd15
--
Summary: [OOP] Derived type with GENERIC: resolved to the wrong
specific TBP
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: burnus at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43945
More information about the Gcc-bugs
mailing list