[J3] 15.5.2.5 Allocatable and pointer dummy variables

José Rui Faustino de Sousa jrfsousa at gmail.com
Tue Sep 1 08:49:55 EDT 2020


Dear All,

First of all I would like to apologize if this is not the adequate place 
to ask this question.

Shouldn't 15.5.2.5p1 say something like:

"The requirements in this subclause apply to an actual argument with the 
ALLOCATABLE or POINTER attribute that corresponds to a dummy argument 
with the same attribute[, which shall not have the INTENT (IN) attribute]."

Assuming one has a class hierarchy of the type:

type T_0;...

type, extends(T_N) :: T_{N+1};...

If I understand correctly what is pretended to by 15.5.2.5 is to stop 
that one would return an ancestor type to a procedure expecting an 
extended type.

Something like:

subroutine bad_alloc(p)
class(t1), allocatable, intent(inout) :: p
...
allocate(t2::p)
...

program
...
class(t3), allocatable :: q
...
call bad_alloc(q)
...

Which would then proceed to (hopefully) fail when one tried to read the 
extended class instance variables or use it's methods.

But AFAICT if the dummy argument has the intent(in) attribute doing 
anything like this would be impossible.

Reading the responses to F08/0073 and F08/0059 it seems clear that the 
intention is not to impose these requirements on the "auto-targetting" 
feature and the new wording of 15.5.2.5p1 implies that:

Subroutine sp1(p)
Class(t1), pointer, Intent(In) :: p
...

type(t3), target :: x
...
call sp1(x)

Is legal.

But it still seems to forbid code like this:

type(t3), pointer :: pt
...
call sp1(pt)

class(t3), pointer :: pc
...
call sp1(pc)

type(t3), target, allocatable :: at
...
call sp1(at)

class(t3), target, allocatable :: ac
...
call sp1(ac)

And the same interpretation applies to allocatable dummy arguments, 
although the intent(in) attribute would AFAICT avoid the problem, code 
like this:

function sp1(p) result(n)
Class(t1), allocatable, Intent(In) :: p
...

type(t3),  allocatable :: at
...
n = sp1(at)
...

class(t3), allocatable :: ac
...
n = sp1(ac)
...

Seem to be forbidden.

Maybe I am missing the point terribly and if so I apologize.

Thank very much for your time.

Best regards,
José Rui

P.S.- I have included some longer versions of the code snippets.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: m013_b.f90
Type: text/x-fortran
Size: 1112 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20200901/e2ac9605/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: m013_c.f90
Type: text/x-fortran
Size: 936 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20200901/e2ac9605/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: m013_m.f90
Type: text/x-fortran
Size: 1149 bytes
Desc: not available
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20200901/e2ac9605/attachment-0002.bin>


More information about the J3 mailing list