The Fortran 2008 standard says (C456):
The passed-object dummy argument shall be a scalar, nonpointer, nonallocatable dummy data object
with the same declared type as the type being defined (...)
But can a passed-object dummy argument have the TARGET attribute? Should the Intel compiler be able to deal with this?
I am asking because I ran into segfaults with a type-bound function that returned a pointer to an attribute of the passed object. It was solved when I rewrote the code to use a regular subroutine. I'm also a little surprised that the standards committee allowed targets, but not pointers. I would just like to be sure that they did not simply forget to list 'target' in the above specifications.
Of course, it can have the target attribute:
module foo implicit none type :: t1 integer :: n contains procedure :: init => t1_init end type t1 contains subroutine t1_init (t, n_in) integer, intent(in) :: n_in class(t1), intent(out), target :: t t%n = n_in end subroutine t1_init end module foo
Thanks for the reply. If this is actually common usage, then I suspect I just ran into a compiler glitch earlier.
By the way, your code sample does not use the fact that `t` is a target. It just shows that the compiler will not reject it, which I already knew.
No, I didn't make use of it, but is very common, e.g. for types containing run-time data which you want to have also in local instances, and which contain also pointer components like linked lists or parse trees and such. Then you need TBPs where the passed-object dummy argument is indeed a target.