http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53259
Bug #: 53259 Summary: [OOP] virtual call to type bound procedure calls base, not extension? Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: dfra...@gcc.gnu.org CC: ja...@gcc.gnu.org The testcase below strangely calls a_hook, but I'd expect b_hook to be called? For what it's worth, an equivalent testcase in C++ calls b_hook ... $ gfortran hook.f90 && ./a.out hook: a [gfortran 4.8 r186145; info provided by Andrew Benson] See also the thread started here: http://gcc.gnu.org/ml/fortran/2012-05/msg00029.html This may be related to PR53255 (but the workaround given there does not seem to work. Didn't test the patch yet). Testcase: $ cat hook.f90 MODULE m TYPE :: a CONTAINS PROCEDURE :: worker => a_worker PROCEDURE :: hook => a_hook END TYPE TYPE, extends(a) :: b CONTAINS PROCEDURE :: worker => b_worker PROCEDURE :: hook => b_hook END TYPE CONTAINS SUBROUTINE a_worker(this) CLASS(a), INTENT(in) :: this CALL this%hook() END SUBROUTINE SUBROUTINE a_hook(this) CLASS(a), INTENT(in) :: this print *, "hook: a" ! This is wrongly(?) called. END SUBROUTINE SUBROUTINE b_worker(this) CLASS(b), INTENT(in) :: this ! do some extra work, then call the worker of the base class, ! expect to come back to b_hook later ... CALL this%a%worker() END SUBROUTINE SUBROUTINE b_hook(this) CLASS(b), INTENT(in) :: this print *, "hook: b" END SUBROUTINE END MODULE USE m TYPE(b) :: obj CALL obj%worker() END