This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/54389] New: [F2003/F2008 difference] PURE functions and pointer dummy arguments


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54389

             Bug #: 54389
           Summary: [F2003/F2008 difference] PURE functions and pointer
                    dummy arguments
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: diagnostic, rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


Broad up in the comp.lang.fortran "Function questions?" thread
https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.fortran/r4PVbtaBnFM 

Ian Harvey remarks there that Fortran 2008 removed a restriction regarding
PURE. 


Fortran 2003 has:

"C1272   In a pure subprogram any designator with a base object that [...] is a
dummy argument of a pure function, is a dummy argument with INTENT (IN) of a
pure subroutine [...] shall not be used in the following contexts: [...]"


Fortran 2008 changed it to:

"C1283   In a pure subprogram any designator with a base object that [...] is a
dummy argument with the INTENT (IN) attribute [...] shall not be used [...]"


Note: Both standards (F2003:C1266, F2008:C1276) require that all *nonpointer*
dummy arguments to pure *functions* have the INTENT(IN) or VALUE attribute.

However, there is no such restriction for pointers. Hence, an INTENT(OUT) or
INTENT(INOUT) pointer is allowed - also for functions - and it may be used in
pointer assignments (both sides), variable definition contexts etc. - like in a
normal procedure. 


Currently, the following program is rejected with:
  Error: Variable 'ptr' can not appear in a variable definition context
         (assignment) at (1) in PURE procedure

(As a side remark: I wonder whether it should be made clearer that this applies
to a pure FUNCTION rather than to a pure SUBROUTINE. And the error message
feels a bit incomplete, maybe one should add the procedure name at the end.)


  PURE INTEGER FUNCTION foo (ptr)
    INTEGER, INTENT(INOUT), POINTER :: ptr
    ptr = ptr + 1
    foo = 1
  END FUNCTION foo


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]