[Bug fortran/84060] New: Wrong assignment from a class(*) variable which is a function result.

vladimir.fuka at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Jan 26 10:27:00 GMT 2018


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

            Bug ID: 84060
           Summary: Wrong assignment from a class(*) variable which is a
                    function result.
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vladimir.fuka at gmail dot com
  Target Milestone: ---

The following gives random garbage results:


    select type (tmp => getValue())
      type is (integer)
        print *, "tmp",tmp
        int_var = tmp
    end select

    print *, int_var
contains

  function getValue() result(res)
    class(*), allocatable :: res

    res = 5
  end function

end


> gfortran-7 unlimfunction.f90
> ./a.out 
 tmp           5
       32682


That was an expression, but a variable does the same:

    class(*), allocatable :: a

    a = getValue()

    select type (a)
      type is (integer)
        print *, "tmp",a
        int_var = a
    end select

    print *, int_var
contains

  function getValue() result(res)
    class(*), allocatable :: res

    res = 5
  end function

end


> gfortran-7 unlimfunction.f90 -
> ./a.out 
 tmp           5
           0


Changing assignments to sourced allocations changes nothing.


More information about the Gcc-bugs mailing list