1! { dg-do compile }
2! Tests the patch for PR 29641, in which an ICE would occur with
3! the ordering of USE statements below.
4!
5! Contributed by Jakub Jelinek <jakub@gcc.gnu.org>
6!
7module A
8  type :: T
9    integer :: u
10  end type T
11end module A
12
13module B
14contains
15  function foo()
16    use A
17    type(T), pointer :: foo
18    nullify (foo)
19  end function foo
20end module B
21
22subroutine bar()
23  use B             ! The order here is important
24  use A             ! If use A comes before use B, it works
25  type(T), pointer :: x
26  x => foo()
27end subroutine bar
28
29  use B
30  use A
31  type(T), pointer :: x
32  type(T), target  :: y
33  x => y
34  print *, associated (x)
35  x => foo ()
36  print *, associated (x)
37end
38