gfortran rejects valid <protected_pointer>%<component> references, cf. "OK 3" and "OK 4" below. The test case was created by Jared Ahern and the issue was reported to http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/6a866eb893ad8473 Note: The OK/Invalid lines are according to my understanding; no guarantee that those are correct. MODULE amod IMPLICIT NONE TYPE foo INTEGER :: i = 4 INTEGER, POINTER :: j => NULL() END TYPE foo TYPE(foo), SAVE, PROTECTED :: a TYPE(foo), SAVE, PROTECTED, POINTER :: b INTEGER, SAVE, PROTECTED :: i = 5 INTEGER, SAVE, PROTECTED, POINTER :: j => NULL() contains subroutine alloc() allocate(b,j) end subroutine alloc END MODULE amod PROGRAM test USE amod IMPLICIT NONE INTEGER, TARGET :: k TYPE(foo), TARGET :: c k = 2 ! local c%i = 9 ! local call alloc() ! In parentheses: compiler gives error for that line ! gfortran 4.6/Oct, g95 Aug 2010, NAG 5.1, ifort 11.1, ! pathf95 3.2.99, PGI 10.5 (compiles without error), crayftn i = k ! Invalid 1 (gfortran NAG g95 ifort pathf95 cray) j => k ! Invalid 2 (gfortran g95 ifort pathf95 cray) j = 3 ! OK 1 ( ifort pathf95 cray) a = c ! Invalid 3 (gfortran NAG g95 ifort pathf95 cray) a%i = k ! Invalid 4 (gfortran NAG g95 ifort pathf95 cray) a%j => k ! Invalid 5 (gfortran NAG g95 ifort pathf95 cray) a%j = 5 ! OK 2 ( g95 ifort pathf95 cray) b => c ! Invalid 6 (gfortran g95 ifort pathf95 cray) b%i = k ! OK 3 (gfortran ifort [bug] cray) b%j => k ! OK 4 (gfortran g95 ifort [bug] cray) b%j = 5 ! OK 5 ( ifort [bug] cray) END PROGRAM test
Untested patch. Daniel, what do you think? Is such a check also needed elsewhere in gfc_check_vardef_context (e.g. for the PURE check)? --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -4400,7 +4400,7 @@ gfc_check_vardef_context (gfc_expr* e, bool pointer, const char* context) } /* PROTECTED and use-associated. */ - if (sym->attr.is_protected && sym->attr.use_assoc) + if (sym->attr.is_protected && sym->attr.use_assoc && check_intentin) { if (pointer && is_pointer) {
I have to admit that I more or less copied that "check_intentin" business while rewriting the code. It seems to "make sense", but I didn't find (and care to find) this in the standard. So if you think that this is the correct behaviour also for PROTECTED, then I think this patch is what we want. But whether this is correct or we even should do that for PURE is something I have no idea about.
Author: burnus Date: Sat Oct 23 13:48:08 2010 New Revision: 165883 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=165883 Log: 2010-10-23 Tobias Burnus <burnus@net-b.de> PR fortran/46122 * expr.c (gfc_check_vardef_context): Fix PROTECTED check. 2010-10-23 Tobias Burnus <burnus@net-b.de> PR fortran/46122 * gfortran.dg/protected_8.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/protected_8.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/testsuite/ChangeLog
FIXED on the trunk (4.6).