http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45290
--- Comment #11 from janus at gcc dot gnu.org 2011-02-06 17:42:35 UTC --- (In reply to comment #10) > (In reply to comment #9) > > procedure(), pointer :: ptr3 => p2 > > I now believe that this is invalid (all quotes are F2008): > > R505 initialization is [...] or => initial-data-target > R443 initial-data-target is designator > > C461 (R443) The designator shall designate a nonallocatable variable that has > the TARGET and SAVE attributes and does not have a vector subscript. Every > subscript, section subscript, substring starting point, and substring ending > point in designator shall be a constant expression. > > > Well, in the example (cf. also the ICE in comment 5) "p2" is a POINTER and a > pointer cannot have the TARGET attribute (cf. C556). > > Thus, the "initial-data-target" can neither be a pointer nor a proc-pointer. Ok, I agree. Also I remember that we already had some discussion about this when I committed the first patch for this PR, without any consensus. Let's compare the above C461 to the corresponding restriction for normal pointer assignment ... R737 data-target is variable C724 (R737) A variable shall have either the TARGET or POINTER attribute, and shall not be an array section with a vector subscript. ... which explicitly allows both the TARGET and POINTER attribute, while C461 only allows the TARGET attribute. In conclusion, I propose the following patch: Index: gcc/fortran/expr.c =================================================================== --- gcc/fortran/expr.c (revision 169853) +++ gcc/fortran/expr.c (working copy) @@ -3608,7 +3608,7 @@ gfc_check_assign_symbol (gfc_symbol *sym, gfc_expr "must not be ALLOCATABLE "); return FAILURE; } - if (!attr.target) + if (!attr.target || attr.pointer) { gfc_error ("Pointer initialization target at %C " "must have the TARGET attribute"); We have to explicitly demand that the rhs of the pointer initialization does not have the POINTER attribute, since gfc_expr_attr gives the TARGET attribute also to POINTER expressions (probably because the thing that the pointer points to has the TARGET attribute). The patch correctly rejects the two invalid lines in the following test case: module m implicit none type :: t integer, pointer :: p integer :: i end type integer, target :: i type(t), target :: x integer, pointer :: p1 => i integer, pointer :: p2 => p1 ! invalid integer, pointer :: p3 => x%p ! invalid integer, pointer :: p4 => x%i end module m