This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] Polymorphic deep copy (aka PR46174)


On 11/05/2010 10:56 AM, Janus Weil wrote:
I think the problem was the following: The assigment in copy$foo, which is just
   dst = src      !!! both 'dst' and 'src' being TYPE(foo)
was falsely transformed into a call to the typebound assignment
operator, although no polymorphic pass-object was present. I fixed
this by modifying gfc_extend_assign in interface.c.

I am not 100% sure about the code in gfc_extend_assign. In particular, I wonder whether


  if (lhs->ts.type == BT_CLASS)
    {

should not also have "|| lhs->ts.type == BT_TYPE". Though, that probably would just undo what you did in the patch.

I think the following program is valid and now rejected with your patch:

------------------------------------
module m
type t
  integer :: ij
contains
  procedure :: my_assign
  generic :: assignment(=) => my_assign
end type t
contains
  SUBROUTINE my_assign (dest, from)
    CLASS(t), INTENT(INOUT) :: dest
    integer, INTENT(IN) :: from
    dest%ij = -from
  END SUBROUTINE
end module m

use m
type(t) :: x

x = 4
print *, x%ij
end
------------------------------------

Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]