[Bug fortran/42385] [OOP] poylmorphic operators do not work
damian at rouson dot net
gcc-bugzilla@gcc.gnu.org
Fri May 21 14:02:00 GMT 2010
------- Comment #1 from damian at rouson dot net 2010-05-21 14:01 -------
As suggested by Janus and Paul, I'm adding the additional test case below. Note
that the first two pointer assignments in main are not necessary to demonstrate
the linking problem. I put them there (1) to give more detail about what I was
trying to do and (2) because deleting those leaves pointless code since there
would be no reason to do the the third assignment without doing the first two.
$cat link_demo.f03
module field_module
implicit none
type ,abstract :: field
contains
procedure(field_eq_field) ,deferred :: assign
generic :: assignment(=) => assign
end type
abstract interface
subroutine field_eq_field(lhs,rhs)
import :: field
class(field) ,intent(out) :: lhs
class(field) ,intent(in) :: rhs
end subroutine
end interface
end module
module periodic_field_module
use field_module ,only : field
implicit none
type ,extends(field) :: periodic_field
real :: f=0.
contains
procedure :: assign => copy
end type
contains
function new_periodic_field()
type(periodic_field) ,pointer :: new_periodic_field
allocate(new_periodic_field)
end function
subroutine copy(lhs,rhs)
class(field) ,intent(in) :: rhs
class(periodic_field) ,intent(out) :: lhs
select type(rhs)
class is (periodic_field)
lhs%f = rhs%f
class default
stop 'periodic_field%copy: unsupported right-hand-side class.'
end select
end subroutine
end module
program main
use field_module
use periodic_field_module
implicit none
class(field) ,pointer :: u,f
u => new_periodic_field()
f => new_periodic_field()
f = u
end program
$ gfortran link_demo.f03
Undefined symbols:
"_field_eq_field_", referenced from:
_MAIN__ in ccFO42I9.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42385
More information about the Gcc-bugs
mailing list