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

            Bug ID: 89030
           Summary: gfortran accepts invalid code
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: juergen.reuter at desy dot de
  Target Milestone: ---

The following issue was discussed on the Intel forum:
https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/803316
The assignment is accepted by gfortran, but it should be rejected as invalid
code:
x = t(5)

1. The RHS is evaluated as structure constructor for t
2. Then defined assignment sets in, so it is translated into set (x, t(5)),
and here either both x and t must be unlimited polymorphic, or both
have to have the same type.
(if I understand the standard correctly, but Steve Lionel seems to support
this)
Cheers,
    JRR



Short reproducer:


module mod

  implicit none
  private

  type, public :: t
     integer :: i = 3
   contains
     generic, public :: assignment(=) => set
     procedure, private :: set
  end type t

contains

  subroutine set(x, y)
    class(t), intent(out) :: x
    type(t), intent(in) :: y
    print *, "foo"
  end subroutine set

end module mod



program alloc_assign

  use mod
  implicit none
  class(*), allocatable :: x

  x = t(5)

end program alloc_assign

Reply via email to