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

            Bug ID: 99609
           Summary: Pure Function that has a Variable with Value Attribute
                    that is modified
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Boyce at engineer dot com
  Target Milestone: ---

Created attachment 50392
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50392&action=edit
Module that replicates the error

This is a problem I found in all versions of gfortran.

The issue is with the value attribute for a pure function raises an error if
the variable is changed. gfortran assumes that the variable has an intent(in),
but with the value attribute the variable is a copy so the original is not
changed.

For example, the following module raises an error for func1, but not func2.
Functionally the two functions are equivalent, but one explicitly declares the
copy of a.

The attachment contains the same code as the following, but with a PROGRAM/END
PROGRAM driver.

MODULE ex_func
  contains
  !
  ! Does not recognize that value makes a copy of "a"
  !
  pure function func1(a) result(x)
    integer, value :: a
    integer :: x
    !
    a = a*a
    !
    x = a
    !
  end function
  !
  pure function func2(a) result(x)
    integer, intent(in) :: a
    integer :: x
    integer :: tmp
    !
    tmp = a
    tmp = tmp*tmp
    !
    x = tmp
    !
  end function
END MODULE

Reply via email to