public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53255] New: [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one
@ 2012-05-06  8:55 burnus at gcc dot gnu.org
  2012-05-06 10:33 ` [Bug fortran/53255] " burnus at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-05-06  8:55 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53255
           Summary: [OOP] With TYPE, wrong type-bound operator used: of
                    parent instead of overridden one
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


Reported by Reinhold Bader.

Expected: The following output:
 executing base
 executing override
 OK

De-facto output:
 executing base
 executing base
 FAIL


If one changes:
  type(ext) :: p
to
  class(ext), allocatable :: p
  allocate(p)
or
  class(base), allocatable :: p
  allocate(ext :: p)
it works.

Thus, it seems as if only the compile-time resolution of TYPE has the problem,
while the vtable run-time version is correct.



module mod_base
  implicit none
  private
  type, public :: base
     private
     real :: r(2,2) = reshape( (/ 1.0, 2.0, 3.0, 4.0 /), (/ 2, 2 /))
   contains
     procedure, private :: trace
     generic :: operator(.tr.) => trace
  end type base
contains
  complex function trace(this)
    class(base), intent(in) :: this
    trace = this%r(1,1) + this%r(2,2)
  end function trace
end module mod_base
module mod_ext
  use mod_base
  implicit none
  private
  public :: base
  type, public, extends(base) :: ext
     private
     real :: i(2,2) = reshape( (/ 1.0, 1.0, 1.0, 1.5 /), (/ 2, 2 /))
   contains
     procedure, private :: trace => trace_ext
  end type ext
contains
   complex function trace_ext(this)
    class(ext), intent(in) :: this

!   the following should be executed through invoking .tr. p below
    write(*,*) 'executing override'
    trace_ext = .tr. this%base + (0.0, 1.0) * ( this%i(1,1) + this%i(2,2) )
  end function trace_ext

end module mod_ext
program test_override
  use mod_ext
  implicit none
  type(base) :: o
  type(ext) :: p
!  write(*,*) .tr. o
!  write(*,*) .tr. p

  if (abs(.tr. o - 5.0 ) < 1.0e-6  .and. abs( .tr. p - (5.0,2.5)) < 1.0e-6)
then
     write(*,*) 'OK'
  else
     write(*,*) 'FAIL'
  end if
end program test_override


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-05-07 13:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-06  8:55 [Bug fortran/53255] New: [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one burnus at gcc dot gnu.org
2012-05-06 10:33 ` [Bug fortran/53255] " burnus at gcc dot gnu.org
2012-05-07  8:44 ` burnus at gcc dot gnu.org
2012-05-07 11:52 ` burnus at gcc dot gnu.org
2012-05-07 13:35 ` burnus at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).