summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/finalize_5.f03
blob: 1df2d8cf285f7cf9e09b3875c300abbc77a027a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
! { dg-do compile }

! Parsing of finalizer procedure definitions.
! Check for appropriate errors on invalid final procedures.

MODULE final_type
  IMPLICIT NONE

  TYPE :: mytype
    INTEGER, ALLOCATABLE :: fooarr(:)
    REAL :: foobar
    FINAL :: finalize_matrix ! { dg-error "must be inside a derived type" }
  CONTAINS
    FINAL :: ! { dg-error "Empty FINAL" }
    FINAL ! { dg-error "Empty FINAL" }
    FINAL :: + ! { dg-error "Expected module procedure name" }
    FINAL :: iamnot ! { dg-error "is not a SUBROUTINE" }
    FINAL :: finalize_single finalize_vector ! { dg-error "Expected ','" }
    FINAL :: finalize_single, finalize_vector
    FINAL :: finalize_single ! { dg-error "is already defined" }
    FINAL :: finalize_vector_2 ! { dg-error "has the same rank" }
    FINAL :: finalize_single_2 ! { dg-error "has the same rank" }
    FINAL :: bad_function ! { dg-error "is not a SUBROUTINE" }
    FINAL bad_num_args_1 ! { dg-error "must have exactly one argument" }
    FINAL bad_num_args_2 ! { dg-error "must have exactly one argument" }
    FINAL bad_arg_type
    FINAL :: bad_pointer
    FINAL :: bad_alloc
    FINAL :: bad_optional
    FINAL :: bad_intent_out

    ! TODO:  Test for polymorphism, kind parameters once those are implemented.
  END TYPE mytype

CONTAINS

  SUBROUTINE finalize_single (el)
    IMPLICIT NONE
    TYPE(mytype) :: el
  END SUBROUTINE finalize_single

  ELEMENTAL SUBROUTINE finalize_single_2 (el)
    IMPLICIT NONE
    TYPE(mytype), INTENT(IN) :: el
  END SUBROUTINE finalize_single_2

  SUBROUTINE finalize_vector (el)
    IMPLICIT NONE
    TYPE(mytype), INTENT(INOUT) :: el(:)
  END SUBROUTINE finalize_vector

  SUBROUTINE finalize_vector_2 (el)
    IMPLICIT NONE
    TYPE(mytype), INTENT(IN) :: el(:)
  END SUBROUTINE finalize_vector_2
  
  SUBROUTINE finalize_matrix (el)
    IMPLICIT NONE
    TYPE(mytype) :: el(:, :)
  END SUBROUTINE finalize_matrix

  INTEGER FUNCTION bad_function (el)
    IMPLICIT NONE
    TYPE(mytype) :: el

    bad_function = 42
  END FUNCTION bad_function

  SUBROUTINE bad_num_args_1 ()
    IMPLICIT NONE
  END SUBROUTINE bad_num_args_1

  SUBROUTINE bad_num_args_2 (el, x)
    IMPLICIT NONE
    TYPE(mytype) :: el
    COMPLEX :: x
  END SUBROUTINE bad_num_args_2

  SUBROUTINE bad_arg_type (el) ! { dg-error "must be of type 'mytype'" }
    IMPLICIT NONE
    REAL :: el
  END SUBROUTINE bad_arg_type

  SUBROUTINE bad_pointer (el) ! { dg-error "must not be a POINTER" }
    IMPLICIT NONE
    TYPE(mytype), POINTER :: el
  END SUBROUTINE bad_pointer

  SUBROUTINE bad_alloc (el) ! { dg-error "must not be ALLOCATABLE" }
    IMPLICIT NONE
    TYPE(mytype), ALLOCATABLE :: el(:)
  END SUBROUTINE bad_alloc

  SUBROUTINE bad_optional (el) ! { dg-error "must not be OPTIONAL" }
    IMPLICIT NONE
    TYPE(mytype), OPTIONAL :: el
  END SUBROUTINE bad_optional

  SUBROUTINE bad_intent_out (el) ! { dg-error "must not be INTENT\\(OUT\\)" }
    IMPLICIT NONE
    TYPE(mytype), INTENT(OUT) :: el
  END SUBROUTINE bad_intent_out

END MODULE final_type

PROGRAM finalizer
  IMPLICIT NONE
  ! Nothing here, errors above
END PROGRAM finalizer

! TODO: Remove this once finalization is implemented.
! { dg-excess-errors "not yet implemented" }

! { dg-final { cleanup-modules "final_type" } }