public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Potential BUG with array constructor actual argument + unlimited polymorphic assumed shape array dummy argument + allocate with source=
@ 2015-10-14 11:07 Dominique d'Humières
  0 siblings, 0 replies; 3+ messages in thread
From: Dominique d'Humières @ 2015-10-14 11:07 UTC (permalink / raw)
  To: vsande; +Cc: jdelia, GNU GFortran

> Well, at least with: … 6.0.0 20150801 … the test program runs OK, i.e.

Likely fixed by r222361 for pr60322:

https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=222361

Cheers,

Dominique

^ permalink raw reply	[flat|nested] 3+ messages in thread
* Potential BUG with array constructor actual argument + unlimited polymorphic assumed shape array dummy argument + allocate with source=
@ 2015-10-14 10:29 vsande
  2015-10-14 10:53 ` Jorge D'Elia
  0 siblings, 1 reply; 3+ messages in thread
From: vsande @ 2015-10-14 10:29 UTC (permalink / raw)
  To: fortran

Dear all,

when compiling with gfortran 5.1.0 the program
displayed below, and executing it, I obtain the following output
on stdout:

vsande@LSSC-T1700:~$ ./a.out
            2           3           0
            1           2           3
            1           2           3

It seems from this output that the first call to allocate_poly_poly,
is not copying properly the unlimited polymorphic assumed shape array
dummy argument "source_expr" into the newly allocated unlimited polymorphic
allocatable dummy argument "vector", whenever the actual argument 
provided to
"source_expr" is an array constructor. This does not happen in the 
second call
to allocate_poly_poly, whenever the actual argument is an array 
variable, or whenever
"source_expr" dummy argument is declared as integer, intent(in) :: 
source_expr(:), even
when the array constructor is passed; see call to subroutine 
allocate_poly_integer.

Am I doing something wrong with to the Fortran200X standard? Is this a 
BUG of the
gfortran 5.1.0 compiler?

I did the same test with ifort 14.0.1 with the following (expected) results:

vsande@LSSC-T1700:~$ ifort test.f90
vsande@LSSC-T1700:~$ ./a.out
            1           2           3
            1           2           3
            1           2           3

Thanks for your help in advance.
Best regards,
  Víctor.


program test
   implicit none
   class(*), allocatable :: v(:)
   integer :: iv(3) = (/1,2,3/)

   ! 1st call
   call allocate_poly_poly ( v, (/1,2,3/) )
   select type ( p=>v )
   type is ( integer )
     write(*,*) p
   end select
   deallocate(v)

   ! 2nd call
   call allocate_poly_poly ( v, iv )
   select type ( p=>v )
   type is ( integer )
     write(*,*) p
   end select
   deallocate(v)

   call allocate_poly_integer ( v, (/1,2,3/) )
   select type ( p=>v )
   type is ( integer )
     write(*,*) p
   end select
   deallocate(v)

contains
   subroutine allocate_poly_poly ( vector, source_expr )
     implicit none
     class(*), allocatable, intent(out) :: vector(:)
     class(*)             , intent(in)  :: source_expr(:)
     allocate(vector(size(source_expr)), source=source_expr)
   end subroutine

   subroutine allocate_poly_integer ( vector, source_expr )
     implicit none
     class(*), allocatable, intent(out) :: vector(:)
     integer             , intent(in)  :: source_expr(:)
     allocate(vector(size(source_expr)), source=source_expr)
   end subroutine
end program

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

end of thread, other threads:[~2015-10-14 11:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-14 11:07 Potential BUG with array constructor actual argument + unlimited polymorphic assumed shape array dummy argument + allocate with source= Dominique d'Humières
  -- strict thread matches above, loose matches on Subject: below --
2015-10-14 10:29 vsande
2015-10-14 10:53 ` Jorge D'Elia

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).