2017-12-08 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gfortran.dg / char_assign_1.f90
blob0d31cee7a1531aca0f524e3b930b33b1b3481de1
1 ! { dg-do run }
2 ! { dg-options "-Wcharacter-truncation" }
3 ! Tests the fix for PR31266: references to CHARACTER
4 ! components lead to the wrong length being assigned to substring
5 ! expressions.
6 type data
7 character(len=5) :: c
8 end type data
9 type(data), dimension(5), target :: y
10 character(len=2), dimension(5) :: p
11 character(len=3), dimension(5) :: q
13 y(:)%c = "abcdef" ! { dg-warning "in assignment \\(5/6\\)" }
14 p(1) = y(1)%c(3:) ! { dg-warning "in assignment \\(2/3\\)" }
15 if (p(1).ne."cd") call abort()
17 p(1) = y(1)%c ! { dg-warning "in assignment \\(2/5\\)" }
18 if (p(1).ne."ab") call abort()
20 q = "xyz"
21 p = q ! { dg-warning "CHARACTER expression will be truncated in assignment \\(2/3\\)" }
22 if (any (p.ne.q(:)(1:2))) call abort()
23 end