[Bug fortran/101199] program changes the value of a dummy argument

ygalklein at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Jun 25 05:55:17 GMT 2021


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

--- Comment #1 from ygal klein <ygalklein at gmail dot com> ---
The problem stays for even a smaller example program:

``` fortran
module mod_original_struct
    implicit none

    private
    public :: extended_struct

    type original_struct
        private
        real, PUBLIC :: var1
        contains

        private
        procedure, public :: init=>initoriginal_struct
    end type original_struct

    type, extends(original_struct) :: extended_struct
        private
        contains
        private
        procedure, public :: init=>initextended_struct, advance
    end type extended_struct

    contains

    subroutine advance(this)
        class(extended_struct), intent(inout) :: this
        print*, 'head of advance, this%var1 = ', this%var1
        call this%init(var1=this%var1)
    end subroutine advance

    subroutine initoriginal_struct(this, var1)
        class(original_struct), intent(out) :: this
        real, intent(in) :: var1
        this%var1 = var1
    end subroutine initoriginal_struct

    subroutine initextended_struct(this, var1)
        class(extended_struct), intent(out) :: this
        real, intent(in) :: var1   
        print*, 'head of initextended_struct, the input argument var1 = ', var1
        this%var1 = var1
    end subroutine initextended_struct

end module mod_original_struct

program example
    use mod_original_struct, only: extended_struct
    implicit none
    type(extended_struct) :: extended1
    call extended1%init(var1=10.)
    print*, 'bf advance, extended1%var1 = ', extended1%var1
    call extended1%advance()
end program example
```

This is the wrong output coming from all gfortran versions (4.8.2, 5.4, 6.4,
7.3, 8.2, 9.3, 10.3 and 11.1):

 head of initextended_struct, the input argument var1 =    10.000000000000000  
   bf advance, extended1%var1 =    10.000000000000000     
 head of advance, this%var1 =    10.000000000000000     
 head of initextended_struct, the input argument var1 =    0.0000000000000000 

the dummy argument var1 changed its value at entrance to init from advance.

using intel 2020u4 provides the right output.

as presented in the first comment: The problem


More information about the Gcc-bugs mailing list