1! { dg-do run }
2! { dg-options "-O2" }
3! Tests the fix for PR29428, in which the assignment of
4! a function result would result in the function being
5! called twice, if it were not a result by reference,
6! because of a spurious nullify in gfc_trans_scalar_assign.
7!
8! Contributed by Paul Thomas  <pault@gcc.gnu.org>
9!
10program test
11implicit none
12
13  type A
14    integer, allocatable :: j(:)
15  end type A
16
17  type(A):: x
18  integer :: ctr = 0
19
20  x = f()
21
22  if (ctr /= 1) call abort ()
23
24contains
25
26  function f()
27    type(A):: f
28      ctr = ctr + 1
29      f = A ((/1,2/))
30  end function f
31
32end program
33
34