summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/pr106731.f90
blob: 470830c706956f73e88626d915f73200e112b4a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
! { dg-do run }
! PR106731 ICE on automatic array of derived type
module causes_ice
    implicit none

    type :: t
        real(8) :: x
        contains
        procedure, private :: write_formatted
        generic :: write(formatted) => write_formatted
    end type t

    contains

    subroutine write_formatted(this, unit, iotype, v_list, iostat, iomsg)
       class(t), intent(in) :: this
       integer, intent(in) :: unit
       character(*), intent(in) :: iotype
       integer, intent(in) :: v_list(:)
       integer, intent(out) :: iostat
       character(*), intent(inout) :: iomsg
       write(unit, '(a,3x,f10.5)', iostat=iostat, iomsg=iomsg) 'dummy', this%x
    end subroutine write_formatted

end module causes_ice

module use_t
    use causes_ice
    implicit none

    public :: automatic_alloc

    contains

    subroutine automatic_alloc(n)
        integer, intent(in) :: n

        ! Automatic array: ICE!
        type(t) :: automatic(n)

        ! Allocatable: works
        type(t), allocatable :: alloc(:)
        allocate(alloc(n))
        
        automatic%x = 42.34675_8

        ! Do anything
        print *, 'n=',n,automatic%x
        print *, 'n=',n,automatic

    end subroutine automatic_alloc

end module use_t

program test
    use use_t
    call automatic_alloc(1)
end program test