Debian Codegraph @

gcc/testsuite/gfortran.dg/f_c_string1.f90

raw
1 !
2 ! { dg-do run }
3 !
4 ! PR117643 F_C_STRING from F23 is missing.
5 ! Test case and initial patch provided by Steve Kargl.
6 program foo
7
8 use iso_c_binding, only : c_null_char, c_char, f_c_string, c_size_t
9
10 implicit none
11
12 logical asis
13 character(len=6, kind=c_char) :: s1
14 character(len=:, kind=c_char), allocatable :: s2
15
16 interface
17 !
18 ! strlen() counts up to '\0', and excludes it from the count
19 !
20 function strlen(s) bind(c,name="strlen")
21 import c_char, c_size_t
22 integer(c_size_t) strlen
23 character(len=1,kind=c_char), intent(in) :: s(*)
24 end function strlen
25 end interface
26
27 s1 = 'abc '
28 s2 = f_c_string(s1)
29 if (len_trim(s1) /= int(strlen(s2), 4)) stop 1
30
31 s1 = ' ghij '
32 s2 = f_c_string(s1)
33 if (len_trim(s1) /= int(strlen(s2), 4)) stop 2
34
35 s2 = f_c_string(s1, .true.)
36 if (len(s1) /= int(strlen(s2), 4)) stop 3
37
38 s2 = f_c_string(s1, .false.)
39 if (len_trim(s1) /= int(strlen(s2), 4)) stop 4
40
41 asis = .true.
42 s2 = f_c_string(s1, asis)
43 if (len(s1) /= int(strlen(s2), 4)) stop 5
44
45 asis = .false.
46 s2 = f_c_string(s1, asis)
47 if (len_trim(s1) /= int(strlen(s2), 4)) stop 6
48
49 end program foo