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

           Summary: [OOP] undefined reference for virtual hook
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: dfra...@gcc.gnu.org
                CC: ja...@gcc.gnu.org


The code below fails to compile due to an undefined reference to the virtual
hook. I have no idea if this is valid Fortran of any standard, but if it isn't,
I'd expect a warning or an error, if it is, I'd like to have an executable
program :)

I currently do not have any 4.5 around, so only tested with trunk.

$> gfortran-svn hook.f90 
/tmp/ccZb2JsG.o: In function `__abstract_weight_policy_MOD_init':
hook.f90:(.text+0x26): undefined reference to `init_hook_'
collect2: ld returned 1 exit status

$> $ gfortran-svn -v
gcc version 4.6.0 20101226 (experimental) (GCC) 

$ cat hook.f90 
MODULE abstract_weight_policy
  TYPE, ABSTRACT :: abstract_weight
    PRIVATE
    INTEGER :: n, a
  CONTAINS
    PROCEDURE                          :: init
    PROCEDURE(hook), PRIVATE, DEFERRED :: init_hook
  END TYPE

  ABSTRACT INTERFACE
    FUNCTION hook(this, n)
      IMPORT :: abstract_weight
      CLASS(abstract_weight), INTENT(inout) :: this
      INTEGER :: n, hook
    END FUNCTION
  END INTERFACE

CONTAINS
  SUBROUTINE init(this, n)
    CLASS(abstract_weight), INTENT(inout) :: this
    INTEGER, INTENT(in) :: n
    this%n = n
    this%a = init_hook(this, n)
  END SUBROUTINE
END MODULE

MODULE myweights_policy
  USE abstract_weight_policy
  TYPE, EXTENDS(abstract_weight) :: myweights
  CONTAINS
    PROCEDURE :: init_hook => myweights_init
  END TYPE
CONTAINS
  FUNCTION myweights_init(this, n)
    CLASS(myweights), INTENT(inout) :: this
    INTEGER                         :: n, myweights_init, k
    myweights_init = SUM((/ (k, k=1, n) /))
  END FUNCTION
END MODULE

PROGRAM test
  USE myweights_policy
  TYPE(myweights) :: w
  CALL w%init(10)
END PROGRAM

Reply via email to