public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* 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

* Re: Potential BUG with array constructor actual argument + unlimited polymorphic assumed shape array dummy argument + allocate with source=
  2015-10-14 10:29 Potential BUG with array constructor actual argument + unlimited polymorphic assumed shape array dummy argument + allocate with source= vsande
@ 2015-10-14 10:53 ` Jorge D'Elia
  0 siblings, 0 replies; 3+ messages in thread
From: Jorge D'Elia @ 2015-10-14 10:53 UTC (permalink / raw)
  To: Gfortran List; +Cc: vsande

Hi Víctor,

Well, at least with:

$ gfortran --version
GNU Fortran (GCC) 6.0.0 20150801 (experimental)
Copyright (C) 2015 Free Software Foundation, Inc.

the test program runs OK, i.e.

$ gfortran -o testpoly.exe testpoly.f90
$ ./testpoly.exe             
           1           2           3
           1           2           3
           1           2           3

Regards,
Jorge.

----- Mensaje original -----
> De: "vsande" <vsande@cimne.upc.edu>
> Para: fortran@gcc.gnu.org
> Enviados: Miércoles, 14 de Octubre 2015 7:31:44
> Asunto: Potential BUG with array constructor actual argument + unlimited polymorphic assumed shape array dummy
> argument + allocate with source=
> 
> 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
> 

-- 
CIMEC (UNL-CONICET), http://www.cimec.org.ar/
Predio CONICET-Santa Fe, Colec. Ruta Nac. 168, 
Paraje El Pozo, S3000GLN, Santa Fe, ARGENTINA. 
Tel +54-342-4511594/95 ext 7062, fax: +54-342-4511169

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

* 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

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 10:29 Potential BUG with array constructor actual argument + unlimited polymorphic assumed shape array dummy argument + allocate with source= vsande
2015-10-14 10:53 ` Jorge D'Elia
2015-10-14 11:07 Dominique d'Humières

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