public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/99609] New: Pure Function that has a Variable with Value Attribute that is modified
@ 2021-03-15 23:09 Boyce at engineer dot com
  2021-03-16  0:34 ` [Bug fortran/99609] " kargl at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Boyce at engineer dot com @ 2021-03-15 23:09 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-03-18 21:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15 23:09 [Bug fortran/99609] New: Pure Function that has a Variable with Value Attribute that is modified Boyce at engineer dot com
2021-03-16  0:34 ` [Bug fortran/99609] " kargl at gcc dot gnu.org
2021-03-16 13:16 ` burnus at gcc dot gnu.org
2021-03-18  3:22 ` Boyce at engineer dot com
2021-03-18  3:28 ` jvdelisle at gcc dot gnu.org
2021-03-18 21:20 ` anlauf at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).