xref: /llvm-project/flang/test/Semantics/associate01.f90 (revision f025e411747ea18fb5c2928103438de98a438c68)
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
2! Tests of selectors whose defining expressions are pointer-valued functions;
3! they must be valid targets, but not pointers.
4! (F'2018 11.1.3.3 p1) "The associating entity does not have the ALLOCATABLE or
5! POINTER attributes; it has the TARGET attribute if and only if the selector
6! is a variable and has either the TARGET or POINTER attribute."
7module m1
8  type t
9   contains
10    procedure, nopass :: iptr
11  end type
12 contains
13  function iptr(n)
14    integer, intent(in), target :: n
15    integer, pointer :: iptr
16    !WARNING: Pointer target is not a definable variable
17    !BECAUSE: 'n' is an INTENT(IN) dummy argument
18    iptr => n
19  end function
20  subroutine test
21    type(t) tv
22    integer, target :: itarget
23    integer, pointer :: ip
24    associate (sel => iptr(itarget))
25      ip => sel
26      !ERROR: POINTER= argument of ASSOCIATED() must be a pointer
27      if (.not. associated(sel)) stop
28    end associate
29    associate (sel => tv%iptr(itarget))
30      ip => sel
31      !ERROR: POINTER= argument of ASSOCIATED() must be a pointer
32      if (.not. associated(sel)) stop
33    end associate
34    associate (sel => (iptr(itarget)))
35      !ERROR: In assignment to object pointer 'ip', the target 'sel' is not an object with POINTER or TARGET attributes
36      ip => sel
37      !ERROR: POINTER= argument of ASSOCIATED() must be a pointer
38      if (.not. associated(sel)) stop
39    end associate
40    associate (sel => 0 + iptr(itarget))
41      !ERROR: In assignment to object pointer 'ip', the target 'sel' is not an object with POINTER or TARGET attributes
42      ip => sel
43      !ERROR: POINTER= argument of ASSOCIATED() must be a pointer
44      if (.not. associated(sel)) stop
45    end associate
46  end subroutine
47end module
48