public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/43945]  New: [OOP] Derived type with GENERIC: resolved to the wrong specific TBP
@ 2010-04-30  9:25 burnus at gcc dot gnu dot org
  2010-04-30  9:25 ` [Bug fortran/43945] " sfilippone at uniroma2 dot it
                   ` (30 more replies)
  0 siblings, 31 replies; 32+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-04-30  9:25 UTC (permalink / raw)
  To: gcc-bugs

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


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

end of thread, other threads:[~2010-07-13  9:12 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-30  9:25 [Bug fortran/43945] New: [OOP] Derived type with GENERIC: resolved to the wrong specific TBP burnus at gcc dot gnu dot org
2010-04-30  9:25 ` [Bug fortran/43945] " sfilippone at uniroma2 dot it
2010-04-30  9:36 ` burnus at gcc dot gnu dot org
2010-04-30  9:42 ` sfilippone at uniroma2 dot it
2010-04-30  9:43 ` sfilippone at uniroma2 dot it
2010-04-30  9:43 ` sfilippone at uniroma2 dot it
2010-04-30 14:33 ` pault at gcc dot gnu dot org
2010-05-01 17:17 ` pault at gcc dot gnu dot org
2010-05-05 21:05 ` pault at gcc dot gnu dot org
2010-06-06  2:04 ` janus at gcc dot gnu dot org
2010-06-06  2:29 ` janus at gcc dot gnu dot org
2010-06-06  2:49 ` janus at gcc dot gnu dot org
2010-06-06  3:03 ` janus at gcc dot gnu dot org
2010-06-06 16:21 ` janus at gcc dot gnu dot org
2010-06-07  8:26 ` sfilippone at uniroma2 dot it
2010-06-07  8:27 ` sfilippone at uniroma2 dot it
2010-06-07  9:41 ` burnus at gcc dot gnu dot org
2010-06-08 14:09 ` sfilippone at uniroma2 dot it
2010-06-16 10:32 ` sfilippone at uniroma2 dot it
2010-06-16 10:32 ` sfilippone at uniroma2 dot it
2010-06-21 11:01 ` janus at gcc dot gnu dot org
2010-06-23 12:20 ` sfilippone at uniroma2 dot it
2010-06-25 15:32 ` sfilippone at uniroma2 dot it
2010-06-25 15:35 ` sfilippone at uniroma2 dot it
2010-07-06 10:14 ` sfilippone at uniroma2 dot it
2010-07-06 10:15 ` sfilippone at uniroma2 dot it
2010-07-07 13:15 ` sfilippone at uniroma2 dot it
2010-07-07 14:25 ` sfilippone at uniroma2 dot it
2010-07-11  9:40 ` janus at gcc dot gnu dot org
2010-07-13  8:54 ` burnus at gcc dot gnu dot org
2010-07-13  9:07 ` sfilippone at uniroma2 dot it
2010-07-13  9:12 ` burnus at gcc dot gnu dot 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).