Debian Codegraph @

gcc/testsuite/gfortran.dg/class_array_24.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-O2 -fdump-tree-optimized" }
3 !
4 ! PR fortran/123961 - SIZE and class array valued constructors and functions
5
6 module test_overload_m
7 implicit none
8
9 type :: foo_t
10 end type foo_t
11
12 interface foo_t
13 module procedure foo_t_0_
14 module procedure foo_t_1_
15 module procedure foo_c_0_
16 module procedure foo_c_1_
17 end interface foo_t
18
19 contains
20
21 function foo_t_0_(i) result(foo)
22 integer, intent(in) :: i
23 type(foo_t), allocatable :: foo
24 allocate (foo)
25 end function foo_t_0_
26
27 function foo_t_1_(i) result(foo)
28 integer, intent(in) :: i(:)
29 type(foo_t), allocatable :: foo(:)
30
31 allocate (foo(size (i)))
32 end function foo_t_1_
33
34 function foo_c_0_(r) result(foo)
35 real, intent(in) :: r
36 class(foo_t), allocatable :: foo
37 allocate (foo)
38 end function foo_c_0_
39
40 function foo_c_1_(r) result(foo)
41 real, intent(in) :: r(:)
42 class(foo_t), allocatable :: foo(:)
43
44 allocate (foo(size (r)))
45 end function foo_c_1_
46
47 end module test_overload_m
48
49 program test_overload
50 use test_overload_m
51 implicit none
52
53 if (size (foo_t([1,2,3])) /= 3) stop 1 ! Optimized
54 if (size (foo_t([1.,2.])) /= 2) stop 2 ! Optimized
55
56 end program test_overload
57
58 ! { dg-final { scan-tree-dump-not "_gfortran_error_stop_numeric" "optimized" } }