- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Assume the following example:
PROGRAM main
IMPLICIT NONE
INTEGER :: res
INTEGER :: val = 10
res = func1(val, func)
CALL sub1(val, func)
CONTAINS
PURE FUNCTION func(a)
IMPLICIT NONE
INTEGER :: func
INTEGER, INTENT(IN) :: a
func = a + 1
END FUNCTION func
PURE FUNCTION func1(a, ptr)
IMPLICIT NONE
INTEGER :: func1
INTEGER, INTENT(IN) :: a
PROCEDURE(func),POINTER, INTENT(IN) :: ptr
func1 = func2(a, ptr) !! Compile-time error: ptr: #6780: A dummy argument with the INTENT(IN) attribute shall not be defined nor become undefined.
END FUNCTION func1
PURE FUNCTION func2(b, ptr)
IMPLICIT NONE
INTEGER :: func2
INTEGER, INTENT(IN) :: b
PROCEDURE(func), POINTER, INTENT(IN) :: ptr
func2 = ptr(b)
END FUNCTION func2
PURE SUBROUTINE sub1(a, ptr)
IMPLICIT NONE
INTEGER, INTENT(INOUT) :: a
PROCEDURE(func),POINTER, INTENT(IN) :: ptr
CALL sub2(a, ptr) !! All right.
END SUBROUTINE sub1
PURE SUBROUTINE sub2(b, ptr)
IMPLICIT NONE
INTEGER, INTENT(INOUT) :: b
PROCEDURE(func), POINTER, INTENT(IN) :: ptr
b = ptr(b)
END SUBROUTINE sub2
END PROGRAM main
The call to sub2 in sub1 triggers nothing while compile-time error raised in its corresponding function version. so what's the difference ?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
seems gfortran does not like the calls in the main program:
gfortran repro2.f90
repro2.f90:7:21:
7 | res = func1(val, func)
| 1
Error: Expected a procedure pointer for argument ‘ptr’ at (1)
repro2.f90:8:19:
8 | CALL sub1(val, func)
| 1
Error: Expected a procedure pointer for argument ‘ptr’ at (1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The usage of ptr as actual argument to func2 in func1 doesn't imply any modification but the error message said so.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@s12 wrote:.. what's the difference ?
A compiler bug, hopefully the Intel Support team will file an incident report for you.
In the meantime, see if you can manage without the "pointer" and "intent(in)" on the procedure argument and do with a more straightforward alternative that is similar to the Fortran "classic" EXTERNAL argument but with an explicit interface:
PROGRAM main
IMPLICIT NONE
INTEGER :: res
INTEGER :: val = 10
res = func1(val, func)
CALL sub1(val, func)
CONTAINS
PURE FUNCTION func(a)
IMPLICIT NONE
INTEGER :: func
INTEGER, INTENT(IN) :: a
func = a + 1
END FUNCTION func
PURE FUNCTION func1(a, ptr)
IMPLICIT NONE
INTEGER :: func1
INTEGER, INTENT(IN) :: a
PROCEDURE(func) :: ptr
func1 = func2(a, ptr)
END FUNCTION func1
PURE FUNCTION func2(b, ptr)
IMPLICIT NONE
INTEGER :: func2
INTEGER, INTENT(IN) :: b
PROCEDURE(func) :: ptr
func2 = ptr(b)
END FUNCTION func2
PURE SUBROUTINE sub1(a, ptr)
IMPLICIT NONE
INTEGER, INTENT(INOUT) :: a
PROCEDURE(func) :: ptr
CALL sub2(a, ptr) !! All right.
END SUBROUTINE sub1
PURE SUBROUTINE sub2(b, ptr)
IMPLICIT NONE
INTEGER, INTENT(INOUT) :: b
PROCEDURE(func) :: ptr
b = ptr(b)
END SUBROUTINE sub2
END PROGRAM main
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for reporting this, @s12. I filed a bug report, CMPLRLLVM-56500. I'll let you know when it's fixed.
Thank you, @FortranFan, for the workaround.
Another workaround is to remove the PURE attribute from FUNCTION func1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page