ieee_9.f90: XFAIL on arm*-*-gnueabi[hf].
[official-gcc.git] / gcc / testsuite / gfortran.dg / extends_2.f03
blob9456e30c7b1d5e130ea66dc7942a750ab32f7180
1 ! { dg-do run }
2 ! A test of f95 style constructors with derived type extension.
4 ! Contributed by Paul Thomas  <pault@gcc.gnu.org>
6 module persons
7   type :: person
8     character(24) :: name = ""
9     integer :: ss = 1
10   end type person
11 end module persons
13 module person_education
14   use persons
15   type, extends(person) :: education
16     integer ::  attainment = 0
17     character(24) :: institution = ""
18   end type education
19 end module person_education
21   use person_education
22   type, extends(education) :: service
23     integer :: personnel_number = 0
24     character(24) :: department = ""
25   end type service
27   type, extends(service) :: person_record
28     type (person_record), pointer :: supervisor => NULL ()
29   end type person_record
31   type(person_record), pointer :: recruit, supervisor
33 ! Check that simple constructor works
34   allocate (supervisor)
35   supervisor%service = service ("Joe Honcho", 123455, 100, &
36                                 "Celestial University", 1, &
37                                 "Directorate")
39   recruit => entry ("John Smith", 123456, 1, "Bog Hill High School", &
40                     99, "Records", supervisor)
42   if (trim (recruit%name) /= "John Smith") STOP 1
43   if (recruit%name /= recruit%service%name) STOP 2
44   if (recruit%supervisor%ss /= 123455) STOP 3
45   if (recruit%supervisor%ss /= supervisor%person%ss) STOP 4
47   deallocate (supervisor)
48   deallocate (recruit)
49 contains
50   function entry (name, ss, attainment, institution, &
51                   personnel_number, department, supervisor) result (new_person)
52     integer :: ss, attainment, personnel_number
53     character (*) :: name, institution, department
54     type (person_record), pointer :: supervisor, new_person
56     allocate (new_person)
58 ! Check nested constructors
59     new_person = person_record (education (person (name, ss), &
60                                 attainment, institution), &
61                                 personnel_number, department, &
62                                 supervisor)
63   end function
64 end