Potential BUG with array constructor actual argument + unlimited polymorphic assumed shape array dummy argument + allocate with source=
vsande
vsande@cimne.upc.edu
Wed Oct 14 10:29:00 GMT 2015
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
More information about the Fortran
mailing list