llvm-project/flang/test/Semantics/definable04.f90
Peter Klausler 30d9323055 [flang] Pointers returned from functions are not definable as pointers
A reference to a pointer-valued function is a "variable" in the argot of
the Fortran standard, and can be the left-hand side of an assignment
statement or passed as a definable actual argument -- but it is not a
definable pointer, and cannot be associated with a pointer dummy argument
that is not INTENT(IN).

Differential Revision: https://reviews.llvm.org/D143827
2023-02-13 15:59:02 -08:00

28 lines
575 B
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1
module m
integer, target :: n
contains
function ptr()
integer, pointer :: ptr
ptr => n
end
subroutine s1(p)
integer, pointer, intent(in) :: p
end
subroutine s2(p)
integer, pointer, intent(in out) :: p
end
end
program test
use m
integer, pointer :: p
p => ptr() ! ok
ptr() = 1 ! ok
call s1(ptr()) ! ok
call s1(null()) ! ok
!ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'p=' is not definable
!BECAUSE: 'ptr()' is not a definable pointer
call s2(ptr())
end