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

Jürgen Reuter <juergen.reuter at desy dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |juergen.reuter at desy dot de

--- Comment #3 from Jürgen Reuter <juergen.reuter at desy dot de> ---
I think that indeed this is not something the compiler needs to do as expected,
as it is an aliasing problem. 
In the advance TBP you are calling again the init routine. The init
routines sets the value of this%var1 to the argument with which it is
called. In this%advance you are calling the init routine with the
argument this%var1. However, in the init routine, the struct1 type
is intent(out), so it is not guaranteed that the value of struct1%var1
is accessible when calling the init routine from an earlier initialization of
that type. That is the aliasing problem: advance calls
the init routine, the init routine creates a new instance of struct1
and you are not guaranteed that you can access the struct1%var1 component.
There are several ways out:
(1) define this in the init routine as intent(inout), very unusual for
    an initializer, but then gfortran does what you expect
(2) define a global instance of struct1 in the module, e.g.
    type(original_struct), save, public :: struct_global
    and in advance then call the (before initialized)
      this%init(struct_global%var1)

Reply via email to