intent(inout) pointer can not be passed as intent(inout) pointer?

intent(inout) pointer can not be passed as intent(inout) pointer?

The following code produces an error.

module inout_inout

contains

subroutine sub1( ptr )

integer, pointer, intent( inout ) :: ptr

nullify( ptr )

end subroutine

subroutine sub2( ptr )

integer, pointer, intent( inout ) :: ptr

nullify( ptr )

call sub1( ptr ) !**** This is the line of the error

end subroutine

end module

The error is this:

Error1 Error: 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. [PTR]S:srcdisk_io_testpointer_to_pointermod.f9022

I'm a little suspicious that there may be a compiler problem since the error message is saying sub2's pointer is intent(in) and not intent(inout), and I can't see why what I have here would be illegal.


5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

This is a compiler bug previously reported - it will be fixed in a future release.

Steve

Is there a public list of open compiler bugs? I am doing things with linked lists and a binary tree, and would like to know of any more pointer related gotcha's.

It seems that there is also a problem with modifying the contents of an object pointed to by an intent(in) pointer.

module pointer_pointer

type data_struct

integer :: int_data

integer, pointer :: int_ptr

end type

contains

subroutine sub1( ptr )

implicit none

type( data_struct ), pointer, intent( in ) :: ptr

type( data_struct ), pointer :: null_ptr => null( )

integer, target :: x

ptr => null_ptr !**** This should cause an error

ptr%int_data = x !**** This should not

ptr%int_ptr => x !**** This should not

end subroutine

subroutine sub2( ptr )

implicit none

type( data_struct ), pointer, intent( in ) :: ptr

type( data_struct ), pointer :: tmp_ptr

integer, target :: x

tmp_ptr => ptr

tmp_ptr%int_data = x

tmp_ptr%int_ptr => x

end subroutine

end module

There are no errors in sub2, and this is the work-around I have for this problem. But the three commented lines in sub1 all

produce errors. I'm a little suspicious since the third line produces the same error as the first line. It seems the compiler

doesn't understand what is going on. These are the errors.

Error1 Error: A pointer dummy argument with the INTENT(IN) attribute shall not appear as an pointer-object in a pointer-assignment-stmt or nullify-stmt. [PTR]S:srcdisk_io_testpointer_to_pointersubr.f9022
Error2 Error: A dummy argument with the INTENT(IN) attribute shall not appear in a variable definition context [PTR]S:srcdisk_io_testpointer_to_pointersubr.f9023
Error3 Error: A pointer dummy argument with the INTENT(IN) attribute shall not appear as an pointer-object in a pointer-assignment-stmt or nullify-stmt. [PTR]S:srcdisk_io_testpointer_to_pointersubr.f9024

There is no public list. Most known errors would be very difficult to describe in a meaningful fashion.

I will need to study your new example - I'll get back to you on Monday. At first glance, Error 1 seems correct but I agree that the other two may not be.

Steve

I agree with the comments in your code - the first assignment should be an error (and is reported as one.) The second and third should be allowed but aren't. I'll report this to the developers. Thanks for bringing it to our attention.

Steve

Login to leave a comment.