3 ! PR fortran/100651 - deferred-length character as optional dummy argument
7 character(:), allocatable
:: err_msg
, msg3(:)
8 character(:), pointer :: err_msg2
=> NULL()
10 ! Subroutines with optional arguments
18 ! Test passing of optional arguments
20 if (.not
. allocated (err_msg
)) stop 1
21 if (len (err_msg
) /= 7) stop 2
22 if (err_msg(1:7) /= "foo bar") stop 3
24 call to_int2 (err_msg
)
25 if (.not
. allocated (err_msg
)) stop 4
26 if (len (err_msg
) /= 7) stop 5
27 if (err_msg(1:7) /= "foo bar") stop 6
30 call to_int_p (err_msg2
)
31 if (.not
. associated (err_msg2
)) stop 11
32 if (len (err_msg2
) /= 8) stop 12
33 if (err_msg2(1:8) /= "poo bla ") stop 13
36 call to_int2_p (err_msg2
)
37 if (.not
. associated (err_msg2
)) stop 14
38 if (len (err_msg2
) /= 8) stop 15
39 if (err_msg2(1:8) /= "poo bla ") stop 16
42 call test_rank1 (msg3
)
43 if (.not
. allocated (msg3
)) stop 21
44 if (len (msg3
) /= 2) stop 22
45 if (size (msg3
) /= 42) stop 23
46 if (any (msg3
/= "ok")) stop 24
51 ! Deferred-length character, allocatable:
52 subroutine assert_code (err_msg0
)
53 character(:), optional
, allocatable
:: err_msg0
54 if (present (err_msg0
)) err_msg0
= 'foo bar'
56 ! Test: optional argument
57 subroutine to_int (err_msg1
)
58 character(:), optional
, allocatable
:: err_msg1
59 call assert_code (err_msg1
)
61 ! Control: non-optional argument
62 subroutine to_int2 (err_msg2
)
63 character(:), allocatable
:: err_msg2
64 call assert_code (err_msg2
)
68 subroutine assert_rank1 (msg
)
69 character(:), optional
, allocatable
, intent(out
) :: msg(:)
70 if (present (msg
)) then
71 allocate (character(2) :: msg(42))
76 subroutine test_rank1 (msg1
)
77 character(:), optional
, allocatable
, intent(out
) :: msg1(:)
78 call assert_rank1 (msg1
)
81 ! Deferred-length character, pointer:
82 subroutine assert_p (err_msg0
)
83 character(:), optional
, pointer :: err_msg0
84 if (present (err_msg0
)) then
85 if (associated (err_msg0
)) deallocate (err_msg0
)
86 allocate (character(8) :: err_msg0
)
91 subroutine to_int_p (err_msg1
)
92 character(:), optional
, pointer :: err_msg1
93 call assert_p (err_msg1
)
96 subroutine to_int2_p (err_msg2
)
97 character(:), pointer :: err_msg2
98 call assert_p (err_msg2
)