public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98573] New: Dynamic type lost on assignment
@ 2021-01-06 19:04 davidhneill at gmail dot com
  2021-01-06 19:12 ` [Bug fortran/98573] " davidhneill at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: davidhneill at gmail dot com @ 2021-01-06 19:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573

            Bug ID: 98573
           Summary: Dynamic type lost on assignment
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidhneill at gmail dot com
  Target Milestone: ---

Created attachment 49904
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49904&action=edit
Minimal reproducer

In the following example, the dynamic type of an unlimited polymorphic array is
lost on an assignment but conserved (as expected) on a sourced allocation.

This happens in all versions I've tried: 7.5.0, 8.4.0, 9.3.0, 10.2.0

My system is Ubuntu 20.04 on Intel hardware with all gfortran versions
installed directly from the Ubuntu repositories.

$ cat type_lost.f90

module foo
  type, public:: box
    class(*), allocatable :: val(:)
  end type
contains
  subroutine store1(this, val)
    class(box), intent(out) :: this
    class(*), intent(in) :: val(:)
    this%val = val
  end subroutine store1
  subroutine store2(this, val)
    class(box), intent(out) :: this
    class(*), intent(in) :: val(:)
    allocate(this%val, source=val)
  end subroutine store2
  subroutine vector_type(val)
    class(*), intent(in) :: val(:)
    select type (val)
    type is (integer)
      print '("INTEGER")'
    class default
      print '("OTHER")'
    end select
  end subroutine vector_type
end module foo

program prog
  use foo
  type(box) :: b
  call store1(b, [1, 2, 3])
  call vector_type(b%val)  ! OTHER
  call store2(b, [1, 2, 3])
  call vector_type(b%val)  ! INTEGER

end program

$ gfortran -g -Wall -Wextra minimal.f90
$ ./a.out
OTHER
INTEGER

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

end of thread, other threads:[~2021-02-20 12:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
2021-01-06 19:12 ` [Bug fortran/98573] " davidhneill at gmail dot com
2021-01-06 19:13 ` davidhneill at gmail dot com
2021-01-06 21:17 ` davidhneill at gmail dot com
2021-01-06 21:18 ` davidhneill at gmail dot com
2021-01-21 18:18 ` pault at gcc dot gnu.org
2021-01-21 18:46 ` dominiq at lps dot ens.fr
2021-01-22 15:01 ` davidhneill at gmail dot com
2021-02-20 12:18 ` dominiq at lps dot ens.fr

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