public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/42385]  New: [OOP] poylmorphic operators do not work
@ 2009-12-15 23:01 janus at gcc dot gnu dot org
  2010-05-21 14:02 ` [Bug fortran/42385] " damian at rouson dot net
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-12-15 23:01 UTC (permalink / raw)
  To: gcc-bugs

Spin-off from PR 42144 (comment #6). As the following code demonstrates,
polymorphic type-bound operators are buggy:


module foo_module
 implicit none
 private
 public :: foo

 type :: foo
 contains
   procedure :: times => times_foo
   procedure :: assign => assign_foo
   generic :: operator(*) => times
   generic :: assignment(=) => assign
 end type

contains

   function times_foo(this,factor) result(product)
     class(foo) ,intent(in) :: this
     class(foo) ,allocatable :: product
     real, intent(in) :: factor
   end function

   subroutine assign_foo(lhs,rhs)
     class(foo) ,intent(inout) :: lhs
     class(foo) ,intent(in) :: rhs
   end subroutine

end module

module bar_module
 use foo_module ,only : foo
 implicit none
 private
 public :: bar

 type ,extends(foo) :: bar
   private
   real :: x=1.
 contains
   procedure :: times => times_bar
   procedure :: assign => assign_bar
 end type

contains
 subroutine assign_bar(lhs,rhs)
   class(bar) ,intent(inout) :: lhs
   class(foo) ,intent(in) :: rhs
   select type(rhs)
     type is (bar)
       lhs%x = rhs%x
   end select
 end subroutine
 function times_bar(this,factor) result(product)
   class(bar) ,intent(in) :: this
   real, intent(in) :: factor
   class(foo), allocatable :: product
   select type(this)
     type is (bar)
       allocate(product,source=this)
       select type(product)
         type is(bar)
           product%x = this%x*factor
       end select
   end select
 end function
end module

program main
 use foo_module ,only : foo
 use bar_module ,only : bar
 implicit none
 type(bar) :: unit
 call rescale(unit,3.141592654)
contains
 subroutine rescale(this,scale)
   class(foo) ,intent(inout) :: this
   real, intent(in) :: scale
   this = this*scale
 end subroutine
end program


This test case is compiled flawlessly, but the generated code is wrong:

rescale (struct .class.foo & restrict this, real(kind=4) & restrict scale)
{
  {
    struct .class.foo.a D.1631;

    D.1631 = times_foo ((struct .class.foo *) this, (real(kind=4) *) scale);
    assign_foo ((struct .class.foo *) this, &D.1631);
  }
}

The operators are always resolved to the base-class procedures. Polymorphic
treatment is missing.


-- 
           Summary: [OOP] poylmorphic operators do not work
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janus at gcc dot gnu dot org


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


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

end of thread, other threads:[~2010-07-20  8:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-15 23:01 [Bug fortran/42385] New: [OOP] poylmorphic operators do not work janus at gcc dot gnu dot org
2010-05-21 14:02 ` [Bug fortran/42385] " damian at rouson dot net
2010-07-12 14:59 ` sfilippone at uniroma2 dot it
2010-07-12 14:59 ` sfilippone at uniroma2 dot it
2010-07-13  9:18 ` burnus at gcc dot gnu dot org
2010-07-13  9:24 ` sfilippone at uniroma2 dot it
2010-07-14 21:43 ` burnus at gcc dot gnu dot org
2010-07-16 13:20 ` pault at gcc dot gnu dot org
2010-07-19 18:49 ` pault at gcc dot gnu dot org
2010-07-19 20:12 ` paul dot richard dot thomas at gmail dot com
2010-07-20  8:09 ` 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).