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: [Patch, fortran] Fix temporary allocation for class assignment.


Dear Paul,

Paul Richard Thomas wrote:
Please reassure me that class array constructors do not, cannot and
will never occur!:-)

Do you mean something like the following:


!------------------------------------
type t
  integer :: i = 5
end type t
type, extends(t) :: t2
  integer :: j = 6
end type t2

class(t), allocatable :: a(:), b(:), c(:)
allocate(t :: a(3))
allocate(t :: b(5))
allocate(t :: c(8))
c = [ a, b ]
select type(c)
  type is(t)
    print '(*(i2))', c%i
  type is(t2)
    print '(*(i2))', c%i
    print '(*(i2))', c%j
end select
end
!------------------------------------

That's accepted by the Cray compiler (7.1.4.111) and produces:
5 5 5 5 5 5 5 5
Though, if one changes "t ::" to "t2 ::", the result is the slightly surprising
5 5 6 6 5 5 5 5
6 5 5 5 6 6 6 6


I think that code is valid Fortran 2003/2008. But to cheer you up: Unlimited polymorphic expressions are not allowed in array constructors (cf. C4107).

Bootstrapped and regtested on Fc9/x86_64 - OK for trunk?

OK. Thanks for the patch.


*************** gfc_trans_create_temp_array (stmtblock_t
+   /* This signals a class array for which we need the size of the
+      dynamic type.  Generate an eltype and then the class expression.  */
+   if (eltype == NULL_TREE&&  initial)

Can you add a small note in the comment before the function which mentions that eltype == NULL_TREE is handed in a special way?


Tobias


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