summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/overload_1.f90
blob: fc38a6c90fec9cead4600356cd8365aa55c53bf7 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
! { dg-do run }
! tests that operator overloading works correctly for operators with
! different spellings
module m
  type t
     integer :: i
  end type t
  
  interface operator (==)
     module procedure teq
  end interface

  interface operator (/=)
     module procedure tne
  end interface

  interface operator (>)
     module procedure tgt
  end interface

  interface operator (>=)
     module procedure tge
  end interface
  
  interface operator (<)
     module procedure tlt
  end interface

  interface operator (<=)
     module procedure tle
  end interface

  type u
     integer :: i
  end type u
  
  interface operator (.eq.)
     module procedure ueq
  end interface

  interface operator (.ne.)
     module procedure une
  end interface

  interface operator (.gt.)
     module procedure ugt
  end interface

  interface operator (.ge.)
     module procedure uge
  end interface
  
  interface operator (.lt.)
     module procedure ult
  end interface

  interface operator (.le.)
     module procedure ule
  end interface

contains
  function teq (a, b)
    logical teq
    type (t), intent (in) :: a, b

    teq = a%i == b%i
  end function teq

  function tne (a, b)
    logical tne
    type (t), intent (in) :: a, b

    tne = a%i /= b%i
  end function tne

  function tgt (a, b)
    logical tgt
    type (t), intent (in) :: a, b

    tgt = a%i > b%i
  end function tgt

  function tge (a, b)
    logical tge
    type (t), intent (in) :: a, b

    tge = a%i >= b%i
  end function tge

  function tlt (a, b)
    logical tlt
    type (t), intent (in) :: a, b

    tlt = a%i < b%i
  end function tlt

  function tle (a, b)
    logical tle
    type (t), intent (in) :: a, b

    tle = a%i <= b%i
  end function tle

  function ueq (a, b)
    logical ueq
    type (u), intent (in) :: a, b

    ueq = a%i == b%i
  end function ueq

  function une (a, b)
    logical une
    type (u), intent (in) :: a, b

    une = a%i /= b%i
  end function une

  function ugt (a, b)
    logical ugt
    type (u), intent (in) :: a, b

    ugt = a%i > b%i
  end function ugt

  function uge (a, b)
    logical uge
    type (u), intent (in) :: a, b

    uge = a%i >= b%i
  end function uge

  function ult (a, b)
    logical ult
    type (u), intent (in) :: a, b

    ult = a%i < b%i
  end function ult

  function ule (a, b)
    logical ule
    type (u), intent (in) :: a, b

    ule = a%i <= b%i
  end function ule
end module m


program main
  call checkt
  call checku

contains
  
  subroutine checkt
    use m

    type (t) :: a, b
    logical :: r1(6), r2(6)
    a%i = 0; b%i = 1

    r1 = (/ a == b, a /= b, a <  b, a <= b, a >  b, a >= b /)
    r2 = (/ a.eq.b, a.ne.b, a.lt.b, a.le.b, a.gt.b, a.ge.b /)
    if (any (r1.neqv.r2)) call abort
    if (any (r1.neqv. &
         (/ .false.,.true.,.true., .true., .false.,.false. /) )) call&
         & abort
  end subroutine checkt

  subroutine checku
    use m

    type (u) :: a, b
    logical :: r1(6), r2(6)
    a%i = 0; b%i = 1

    r1 = (/ a == b, a /= b, a <  b, a <= b, a >  b, a >= b /)
    r2 = (/ a.eq.b, a.ne.b, a.lt.b, a.le.b, a.gt.b, a.ge.b /)
    if (any (r1.neqv.r2)) call abort
    if (any (r1.neqv. &
         (/ .false.,.true.,.true., .true., .false.,.false. /) )) call&
         & abort
  end subroutine checku
end program main
! { dg-final { cleanup-modules "m" } }