Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29275 Discussions

intent(inout) with pointers - mistake or bug?

martinstein
Beginner
746 Views
(The ifort compiler I'm using is Version 10.1, on Linux 64bit.)

I have subroutine SubName with a pointer to an array among the dummy arguments:

subroutine SubName( ..., pointerToArray,...)

integer, dimension(:), pointer, intent(inout)&
:: pointerToArray
...
end subroutine

The pointerToArray occurs in the code of this subroutine in three usages:
(1) allocation of the the array (if not jet associated)
(2) changes to array elements
(3) as an actual argument of a subroutine (again with an intent(inout) attribute for the corresponding dummy argument)

When trying to compile the code, I get an error message. There are no complains about (1) or (2). For the line containing (3) I get

"A pointer dummy argument with the INTENT(IN) attribute shall not appear as an actual argument if the associated dummy argument has the INTENT(OUT) or INTENT(INOUT) attribute"

and refering to the pointerToArray argument. I completely agree that an intent(in) would not allow a call as done in (3). However, I have an intent(inout) attribute which is not what the compiler seems to think for some reason (even so (1) and (2) pass without error).
When I change the intent(inout) attribute to intent(out) in the subroutine SubName, it compiles. Though that's definitely not what I want.

So, do I grasp the concept of intent attributes for pointers introduced in Fortran2003 wrongly or does it more looks like a bug? Any help is greatly appreciated!
Thanks.

0 Kudos
4 Replies
Steven_L_Intel1
Employee
746 Views
I'd feel more confident in responding if I saw an actual and complete test case rather than a paraphrase of what you think the code says. I've been burned too many times by incorrect paraphrasing. Specifically, I'd want to see whether or how an explicit interface for the called routine appears.

FWIW, the INTENT attribute, as it applies to pointers, is for the pointer itself and not the data it points to.
0 Kudos
martinstein
Beginner
746 Views
Well, I have boiled it down to this short module. The compiler is invoked by:

ifort -c -free -auto -warn all SubModule.f90


The Module is:

MODULE SubModule

PUBLIC f
PRIVATE

CONTAINS

subroutine f(ptr)

integer, POINTER, intent(inout) :: ptr

call g(ptr)

end subroutine


!------------------


subroutine g(ptr)

integer, POINTER, intent(inout) :: ptr

if (associated(ptr)) then
write(*,*) 'hello'
end if
end subroutine

END MODULE

The error message remains the same, refering to the argument ptr in the call of g.
0 Kudos
Steven_L_Intel1
Employee
746 Views
Thanks for the concise and complete example. I can reproduce the problem - it's a bug. If you report this to Intel Premier Support, please reference T82717-CP. A workaround is to remove the INTENT attribute from "f".
0 Kudos
Steven_L_Intel1
Employee
746 Views
It turns out that another user reported this problem earlier and the bug has been fixed for a future release.
0 Kudos
Reply