Bug 35837 - rej.valid: Host-associated SAVEd variable and PURE function
Summary: rej.valid: Host-associated SAVEd variable and PURE function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Daniel Kraft
URL:
Keywords: rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2008-04-05 21:54 UTC by Tobias Burnus
Modified: 2008-09-09 09:27 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.4.0
Last reconfirmed: 2008-09-05 12:48:51


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-04-05 21:54:40 UTC
Found this at http://groups.google.com/group/gg95/browse_thread/thread/667fe259fb346773

I think the reporter is right that this program is valid. NAG f95 and ifort accept is without error.

g95 and gfortran reject it with:

Error: SAVE attribute at (1) cannot be specified in a PURE procedure


module g95bug
save
integer :: i=20
contains
pure function tell_i() result (answer)
  integer :: answer
  answer=i
end function tell_i
end module g95bug
Comment 1 Daniel Franke 2008-04-05 22:57:36 UTC
F95, section 12.6 "Pure procedures":

Constraint:   In a pure subprogram any variable which is in common or accessed by host or use association, is a dummy argument to a pure function, is a dummy
argument with INTENT (IN) to a pure subroutine, or an object that is storage
associated with any such variable, shall not be used in the following contexts:
     (1)    As the variable of an assignment-stmt;
     (2)    As a DO variable or implied DO variable;
     (3)    As an input-item in a read-stmt from an internal file;
     (4)    As an internal-file-unit in a write-stmt;
     (5)    As an IOSTAT= specifier in an input or output statement with an
            internal file;
     (6)    As the pointer-object of a pointer-assignment-stmt;
     (7)    As the target of a pointer-assignment-stmt;
     (8)    As the expr of an assignment-stmt in which the variable is of a
            derived type if the derived type has a pointer component at any
            level of component selection;
     (9)    As an allocate-object or stat-variable in an allocate-stmt or
            deallocate-stmt, or as a pointer-object in a nullify-stmt; or
    (10)    As an actual argument associated with a dummy argument with INTENT
            (OUT) or INTENT (INOUT) or with the POINTER attribute.

Thus, the case shown above should be valid.
Comment 2 Daniel Kraft 2008-09-05 20:53:12 UTC
Subject: Bug 35837

Author: domob
Date: Fri Sep  5 20:51:50 2008
New Revision: 140046

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140046
Log:
2008-09-05  Daniel Kraft  <d@domob.eu>

	PR fortran/35837
	* resolve.c (resolve_types): Restore gfc_current_ns on exit.
	* symbol.c (gfc_save_all): Removed blank line.

2008-09-05  Daniel Kraft  <d@domob.eu>

	PR fortran/35837
	* gfortran.dg/save_3.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/save_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Daniel Kraft 2008-09-05 20:55:14 UTC
Fixed for trunk.
Comment 4 Daniel Kraft 2008-09-09 09:26:58 UTC
Subject: Bug 35837

Author: domob
Date: Tue Sep  9 09:25:33 2008
New Revision: 140140

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140140
Log:
2008-09-05  Daniel Kraft  <d@domob.eu>

	PR fortran/35837
	* gfortran.dg/save_3.f90: New test.

2008-09-05  Daniel Kraft  <d@domob.eu>
 
	PR fortran/35837
	* resolve.c (resolve_types): Restore gfc_current_ns on exit.
	* symbol.c (gfc_save_all): Removed blank line.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/save_3.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/resolve.c
    branches/gcc-4_3-branch/gcc/fortran/symbol.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 5 Daniel Kraft 2008-09-09 09:27:49 UTC
Fixed for 4.3 branch.