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

            Bug ID: 67528
           Summary: Wrong result with defined assignment operator and/or
                    parenthesized expressions and allocatable components
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mrestelli at gmail dot com
  Target Milestone: ---

As discussed in

https://groups.google.com/d/msg/comp.lang.fortran/8q2nYfHnZfU/M9FmGgx7AQAJ

gfortran produces wrong results with the attached code (details are
included in the source)


$ gfortran --version
GNU Fortran (GCC) 6.0.0 20150907 (experimental)


module m
 implicit none

 type :: t_a
  real, allocatable :: x
 end type t_a

 interface assignment(=)
  module procedure copy_t_a
 end interface

contains

 subroutine copy_t_a(y,x)
  type(t_a), intent(in)  :: x
  type(t_a), intent(out) :: y
   allocate( y%x , source=x%x)
 end subroutine copy_t_a

end module m


program p
 use m
 implicit none

 type(t_a) :: v1

 ! Define v1
 allocate( v1%x )
 v1%x = 1.5


 ! This produces segfault
 v1 = v1
 write(*,*) "Case A: v1%x = ",v1%x ! should print 1.5

 ! This produces segfault
 !v1 = (v1)
 !write(*,*) "Case B: v1%x = ",v1%x ! should print 1.5

 ! This prints 0
 !call copy_t_a( v1 , (v1) )
 !write(*,*) "Case C: v1%x = ",v1%x ! should print 1.5

end program p

Reply via email to