This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, Fortran, OOP] PR 44541: wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
On Wed, Sep 01, 2010 at 07:01:02PM +0200, Tobias Burnus wrote:
>
> The question is: Why are INTENT(OUT) variables already assigned a value?
> I do not want to change the code until one has understood, why the
> following currently works - or until one has found an example which
> fails the the current code. The following example prints "1":
>
> type t
> integer :: i = 1
> end type t
> type(t) :: a
> a%i = 8
> call init(a)
> print *, a
> contains
> subroutine init(x)
> type(t), intent(out) :: x
> end subroutine
> end
>
16.5.5
(23) Invocation of a procedure that has a nonpointer nonallocatable
INTENT (OUT) dummy argument causes all nonpointer default-initialized
subcomponents of the dummy argument to become defined.
Note there are restrictions on optional arguments.
type t
integer j
integer :: i = 1
end type t
integer :: j = 0
type(t) :: a
a%i = 8
call init(j, a)
print *, a
a%i = 8
call init(j)
print *, a
contains
subroutine init(k, x)
integer, intent(in) :: k
type(t), intent(out), optional :: x
if (k == 1) then
if (present(x)) x%j = k
end if
end subroutine
end
troutmask:sgk[207] gfc4x -o z h.f90
troutmask:sgk[208] ./z
0 1
0 8
--
Steve