Bug 37504 - Wrongly rejects: unprotected_pointer => protected_pointer
Summary: Wrongly rejects: unprotected_pointer => protected_pointer
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: 37513
  Show dependency treegraph
 
Reported: 2008-09-12 21:09 UTC by Tobias Burnus
Modified: 2008-09-26 15:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-09-12 21:09:47 UTC
Found at:
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/73c7b88ffbe8e1d5

The following (see URL above) is valid but gfortran rejects it with:
 Error: Pointer assignment target has PROTECTED attribute at (1)

> C538:
>
> "A pointer object that has the PROTECTED attribute and is accessed by
> use association shall not appear as (1) A pointer-object in a pointer-
> assignment-stmt..."
>
> C538 doesn't forbid using a protected pointer as the target of a
> pointer-assignment-stmt.

module m
  implicit none
  integer, pointer, protected :: protected_pointer
end module m

program p
  use m
  implicit none
  integer, pointer :: unprotected_pointer
  unprotected_pointer => protected_pointer
end program p
Comment 1 Tobias Burnus 2008-09-13 14:48:48 UTC
First patch - completely untested/uncompiled:
Index: expr.c
===================================================================
--- expr.c      (Revision 140340)
+++ expr.c
@@ -3053 +3053,2 @@ gfc_check_pointer_assign (gfc_expr *lval
-  if (attr.is_protected && attr.use_assoc)
+  if (attr.is_protected && attr.use_assoc
+      && !(attr.pointer || attr.proc_pointer))


I don't quite understand why one gets "Error: PROTECTED at (1) only allowed in specification part of a module" for the following example.

module m
  implicit none
  integer, pointer, protected :: protected_pointer
  integer, target, protected :: protected_target
end module m

program p
  use m
  implicit none
  integer, pointer :: unprotected_pointer
  unprotected_pointer => protected_target  ! OK, is rejected
  unprotected_pointer => protected_pointer ! WRONG, is wrongly REJECTED
  protected_pointer => unprotected_pointer ! OK, is rejected, BUT MATCH ERROR
end program p
Comment 2 Tobias Burnus 2008-09-25 15:02:40 UTC
Subject: Bug 37504

Author: burnus
Date: Thu Sep 25 15:01:16 2008
New Revision: 140663

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140663
Log:
2008-09-25  Tobias Burnus  <burnus@net-b.de>

        PR fortran/37504
        * expr.c (gfc_check_pointer_assign): Allow assignment of
        protected pointers.
        * match.c (gfc_match_assignment,gfc_match_pointer_assignment):
        Remove unreachable code.

2008-09-25  Tobias Burnus  <burnus@net-b.de>

        PR fortran/37504
        * gfortran.dg/protected_7.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/protected_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/match.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Tobias Burnus 2008-09-26 15:19:01 UTC
Subject: Bug 37504

Author: burnus
Date: Fri Sep 26 15:17:25 2008
New Revision: 140695

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140695
Log:
2008-09-26  Tobias Burnus  <burnus@net-b.de>

        PR fortran/37504
        * expr.c (gfc_check_pointer_assign): Allow assignment of
        protected pointers.

2008-09-26  Tobias Burnus  <burnus@net-b.de>

        PR fortran/37504
        * gfortran.dg/protected_7.f90: New test.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/protected_7.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/expr.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 4 Tobias Burnus 2008-09-26 15:21:01 UTC
FIXED on the trunk (4.4) and on the 4.3 branch.