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

            Bug ID: 110224
           Summary: Rejects valid: function reference with data pointer
                    result as lhs in assignment
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: neil.n.carlson at gmail dot com
  Target Milestone: ---

According to 9.2 of the F18 standard, a function reference that returns a data
pointer is a variable and can be used in variable definition contexts. In
particular it can be used as the selector in an associate construct (11.1.3.1,
C1101), however gfortran rejects this as invalid as shown by the following
example

module mod
  type :: foo
    real, pointer :: var
  contains
    procedure :: var_ptr
  end type
contains
  function var_ptr(this) result(ref)
    class(foo) :: this
    real, pointer :: ref
    ref => this%var
  end function
end module
program main
  use mod
  type(foo) :: x
  associate (var => x%var_ptr())
    var = 1.0
  end associate
  !x%var_ptr() = 2.0 ! THIS IS NOT REJECTED AS EXPECTED
end program

gfortran-20230612.f90:36:4:

   36 |     var = 1.0
      |    1
Error: ‘var’ at (1) associated to expression cannot be used in a variable
definition context (assignment)

Reply via email to