Yes the code is standard-conforming.
Steve Lionel writes:
> It is not. Note 5.16 even gives an explicit example of this:
Steve has missed the fact that the dummy argument is itself a pointer, so INTENT(IN) applies to the pointer dummy, not to the pointer component of its target.
>NOTE 5.16
>If a dummy argument is a derived-type object with a pointer component, then the pointer as a pointer is a subobject of the dummy >argument, but the target of the pointer is not.
The example in 5.16 does not actually show the declaration, but it is clear from the description that it is an ordinary INTENT(IN) dummy argument, not an INTENT(IN) POINTER. That is, when it says
"For example, if X is a dummy argument of derived type with an integer pointer component P, and X is INTENT (IN),"
It means
TYPE(T),INTENT(IN) :: X
Not
TYPE(T),INTENT(IN),POINTER :: X
The NOTE could be better worded, but at the end of the NOTE it is stated clearly:
"Similarly, the INTENT restrictions on pointer dummy arguments apply only to the association of the dummy argument; they do not restrict the operations allowed on its target."
I repeat, INTENT(IN) does "not restrict the operations allowed on its target", and "o%i => null()" is an operation on the target of the pointer "o", therefore it is not affected by INTENT(IN).
I think I will propose a couple of wording changes (judicious insertion of "nonpointer" in a couple of places) to make this harder to misunderstand.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of Steve Lionel
Sent: Thursday, October 12, 2017 4:06 AM
To: [log in to unmask]
Subject: Re: [COMP-FORTRAN-90] A question on pointer association context of a POINTER subobject of a dummy argument with POINTER as well as INTENT(IN) attribute
On 10/11/2017 10:40 AM, Vipul Parekh wrote:
> Is the following simple code standard-conforming?
>
> module m
>
> type :: t
> integer, pointer :: i
> end type
>
> contains
>
> subroutine sub( o )
> type(t), pointer, intent(in) :: o
> !o => null() !<--- A
> o%i => null() !<--- B
> end subroutine
>
> end module
>
It is not. Note 5.16 even gives an explicit example of this:
NOTE 5.16
If a dummy argument is a derived-type object with a pointer component, then the pointer as a pointer is a subobject of the dummy argument, but the target of the pointer is not.
Therefore, the restrictions on
subobjects of the dummy argument apply to the pointer in contexts where it is used as a pointer, but not in contexts where it is dereferenced to indicate its target. For example, if X is a dummy argument of derived type with an integer pointer component P, and X is INTENT (IN), then the statement X%P => NEW_TARGET is prohibited, ...
Steve
|