2018-09-30 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gfortran.dg / deferred_character_26.f90
blob4f335d720d29ef5930eb730860319b245a95635f
1 ! { dg-do run }
3 ! Test the fix for PR72709 in which the type of the component 'header' is cast
4 ! as character[1:0], which makes it slightly more difficult than usual to
5 ! obtain the element length. This is one and the same bug as PR70752.
7 ! Contributed by 'zmi' <zmi007@gmail.com>
9 program read_exp_data
10 implicit none
12 type experimental_data_t
13 integer :: nh = 0
14 character(len=:), dimension(:), allocatable :: header
16 end type experimental_data_t
18 character(*), parameter :: str(3) = ["#Generated by X ", &
19 "#from file 'Y' ", &
20 "# Experimental 4 mg/g"]
21 type(experimental_data_t) :: ex
22 integer :: nh_len
23 integer :: i
26 nh_len = 255
27 ex % nh = 3
28 allocate(character(len=nh_len) :: ex % header(ex % nh))
30 ex % header(1) = str(1)
31 ex % header(2) = str(2)
32 ex % header(3) = str(3)
34 ! Test that the string length is OK
35 if (len (ex%header) .ne. nh_len) stop 1
37 ! Test the array indexing
38 do i = 1, ex % nh
39 if (trim (ex%header(i)) .ne. trim (str(i))) stop i + 1
40 enddo
42 end program read_exp_data