public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: vsande <vsande@cimne.upc.edu>
To: fortran@gcc.gnu.org
Subject: Potential BUG with array constructor actual argument + unlimited polymorphic assumed shape array dummy argument + allocate with source=
Date: Wed, 14 Oct 2015 10:29:00 -0000	[thread overview]
Message-ID: <561E2F10.4000708@cimne.upc.edu> (raw)

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

             reply	other threads:[~2015-10-14 10:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-14 10:29 vsande [this message]
2015-10-14 10:53 ` Jorge D'Elia
2015-10-14 11:07 Dominique d'Humières

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=561E2F10.4000708@cimne.upc.edu \
    --to=vsande@cimne.upc.edu \
    --cc=fortran@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).