| 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 |
| 12 |
|
| 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") STOP 1 |
| 16 |
|
| 17 |
p(1) = y(1)%c ! { dg-warning "in assignment \\(2/5\\)" } |
| 18 |
if (p(1).ne."ab") STOP 2 |
| 19 |
|
| 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))) STOP 3 |
| 23 |
end |