Bug 23994 - PROTECTED attribute (F2003) is not implemented
PROTECTED attribute (F2003) is not implemented
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.1.0
: P2 enhancement
: ---
Assigned To: Not yet assigned to anyone
:
Depends on:
Blocks: 20585
  Show dependency treegraph
 
Reported: 2005-09-21 10:45 UTC by Francois-Xavier Coudert
Modified: 2006-12-10 23:38 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-05-08 08:37:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2005-09-21 10:45:34 UTC
Fortran 2003 defines the PROTECTED attribute for variables in modules. Example:

-----------------------------------
MODULE temperature
 REAL,PROTECTED :: temp
 CONTAINS
 SUBROUTINE set_temperature
   temp = 0.0
 END SUBROUTINE
END MODULE

use temperature
call set_temperature
print *, temp
temp = 42
end
-----------------------------------

The compiler should issue an error message on that code (temp cannot be modified
from outside the module) but the code should compile fine without the "temp =
42" line.

The only compiler I know that behaves correctly right now is IBM's.
Comment 1 Francois-Xavier Coudert 2005-09-21 11:26:40 UTC
[in answer to pinskia, who added the keyword accepts-invalid]

Currently, gfortran doesn't accept this code:

$ gfortran -std=f2003 a.f90
 In file a.f90:2

 REAL,PROTECTED :: temp
    1
Error: Syntax error in data declaration at (1)

In the future, it should accept the PROTECTED attribute at line 2, and issue an
error (or warning) at line 12. Removing keyword accordingly.
Comment 2 Andrew Pinski 2005-09-21 11:32:20 UTC
I got this wrong because I thought from comment one it was accepting the attribute already but just 
ignoring it.
Comment 3 Francois-Xavier Coudert 2006-05-08 08:37:39 UTC
A good documentation for PROTECTED, in addition to the standard itself, is http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.xlf101a.doc/xlflr/protected.htm
Comment 4 Paul Thomas 2006-11-07 21:41:29 UTC
Have removed the rejects-valid keyword.

Paul
Comment 5 patchapp@dberlin.org 2006-12-10 11:55:25 UTC
Subject: Bug number PR23994

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-12/msg00663.html
Comment 6 Tobias Burnus 2006-12-10 19:53:24 UTC
Subject: Bug 23994

Author: burnus
Date: Sun Dec 10 19:53:07 2006
New Revision: 119709

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119709
Log:
fortran/
2006-12-10  Tobias Burnus  <burnus@net-b.de>

    PR fortran/23994
    * interface.c (compare_actual_formal): PROTECTED is incompatible
with intent(out).
    * symbol.c (check_conflict): Check for PROTECTED conflicts.
      (gfc_add_protected): New function.
      (gfc_copy_attr): Copy PROTECTED attribute.
    * decl.c (match_attr_spec): Add PROTECTED support.
      (gfc_match_protected): New function.
    * dump-parse-tree.c (gfc_show_attr): Add PROTECTED support.
    * gfortran.h (gfc_symbol): Add protected flag.
      Add gfc_add_protected prototype.
    * expr.c (gfc_check_pointer_assign): Add PROTECTED support.
    * module.c (ab_attribute, attr_bits, mio_symbol_attribute,
mio_symbol_attribute):
       Add PROTECTED support.
    * resolve.c (resolve_equivalence): Add PROTECTED support.
    * match.c (gfc_match_assignment,)gfc_match_pointer_assignment:
       Check PROTECTED attribute.
    * match.h: Add gfc_match_protected prototype.
    * parse.c (decode_statement): Match PROTECTED statement.
    * primary.c (match_variable): Add PROTECTED support.

testsuite/
2006-12-10  Tobias Burnus  <burnus@net-b.de>

    PR fortran/23994
    * gfortran.dg/protected_1.f90: New test.
    * gfortran.dg/protected_2.f90: New test.
    * gfortran.dg/protected_3.f90: New test.
    * gfortran.dg/protected_4.f90: New test.
    * gfortran.dg/protected_5.f90: New test.
    * gfortran.dg/protected_6.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/protected_1.f90
    trunk/gcc/testsuite/gfortran.dg/protected_2.f90
    trunk/gcc/testsuite/gfortran.dg/protected_3.f90
    trunk/gcc/testsuite/gfortran.dg/protected_4.f90
    trunk/gcc/testsuite/gfortran.dg/protected_5.f90
    trunk/gcc/testsuite/gfortran.dg/protected_6.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/dump-parse-tree.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/match.h
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 Steven Bosscher 2006-12-10 23:38:05 UTC
Fixed in GCC 4.3