| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Tests fix for PR28425 in which anything other than a constructor would |
| 4 |
! not work for derived type components in a structure constructor. |
| 5 |
! |
| 6 |
! Original version sent by Vivek Rao on 18 Jan 06 |
| 7 |
! Modified by Steve Kargl to remove IO |
| 8 |
! |
| 9 |
module foo_mod |
| 10 |
|
| 11 |
implicit none |
| 12 |
|
| 13 |
type :: date_m |
| 14 |
integer :: month |
| 15 |
end type date_m |
| 16 |
|
| 17 |
type :: file_info |
| 18 |
type(date_m) :: date |
| 19 |
end type file_info |
| 20 |
|
| 21 |
end module foo_mod |
| 22 |
|
| 23 |
program prog |
| 24 |
|
| 25 |
use foo_mod |
| 26 |
|
| 27 |
implicit none |
| 28 |
type(date_m) :: dat |
| 29 |
type(file_info) :: xx |
| 30 |
|
| 31 |
type(date_m), parameter :: christmas = date_m (12) |
| 32 |
|
| 33 |
dat = date_m(1) |
| 34 |
|
| 35 |
xx = file_info(date_m(-1)) ! This always worked - a constructor |
| 36 |
if (xx%date%month /= -1) STOP 1 |
| 37 |
|
| 38 |
xx = file_info(dat) ! This was the original PR - a variable |
| 39 |
if (xx%date%month /= 1) STOP 2 |
| 40 |
|
| 41 |
xx = file_info(foo(2)) ! ...functions were also broken |
| 42 |
if (xx%date%month /= 2) STOP 3 |
| 43 |
|
| 44 |
xx = file_info(christmas) ! ...and parameters |
| 45 |
if (xx%date%month /= 12) STOP 4 |
| 46 |
|
| 47 |
|
| 48 |
contains |
| 49 |
|
| 50 |
function foo (i) result (ans) |
| 51 |
integer :: i |
| 52 |
type(date_m) :: ans |
| 53 |
ans = date_m(i) |
| 54 |
end function foo |
| 55 |
|
| 56 |
end program prog |