PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gfortran.dg / warn_target_lifetime_1.f90
blobfafa0f123bd92d43839bc39cf88f584bb7b964cf
1 ! { dg-do compile }
2 ! { dg-options "-Wtarget-lifetime" }
4 ! PR fortran/54301
6 function f () result (ptr)
7 integer, pointer :: ptr(:)
8 integer, allocatable, target :: a(:)
9 allocate(a(5))
11 ptr => a ! { dg-warning "Pointer at .1. in pointer assignment might outlive the pointer target" }
12 a = [1,2,3,4,5]
13 end function
16 subroutine foo()
17 integer, pointer :: ptr(:)
18 call bar ()
19 contains
20 subroutine bar ()
21 integer, target :: tgt(5)
22 ptr => tgt ! { dg-warning "Pointer at .1. in pointer assignment might outlive the pointer target" }
23 end subroutine bar
24 end subroutine foo
26 function foo3(tgt)
27 integer, target :: tgt
28 integer, pointer :: foo3
29 foo3 => tgt
30 end function
32 subroutine sub()
33 implicit none
34 integer, pointer :: ptr
35 integer, target :: tgt
36 ptr => tgt
38 block
39 integer, pointer :: p2
40 integer, target :: tgt2
41 p2 => tgt2
42 p2 => tgt
43 ptr => p2
44 ptr => tgt
45 ptr => tgt2 ! { dg-warning "Pointer at .1. in pointer assignment might outlive the pointer target" }
46 end block
47 end subroutine sub