hppa64: Fix fmt_f_default_field_width_3.f90 and fmt_g_default_field_width_3.f90
[official-gcc.git] / gcc / testsuite / gfortran.dg / interface_operator_3.f90
blob6a580b2f1cf18fa6c5793f916496b9b282ecd7d8
1 ! { dg-do compile }
2 ! PR fortran/65454 - accept both old and new-style relational operators
4 module m
5 implicit none
6 private :: t1
7 type t1
8 integer :: i
9 end type t1
10 interface operator (==)
11 module procedure :: my_cmp
12 end interface
13 interface operator (/=)
14 module procedure :: my_cmp
15 end interface
16 interface operator (<=)
17 module procedure :: my_cmp
18 end interface
19 interface operator (<)
20 module procedure :: my_cmp
21 end interface
22 interface operator (>=)
23 module procedure :: my_cmp
24 end interface
25 interface operator (>)
26 module procedure :: my_cmp
27 end interface
28 contains
29 elemental function my_cmp (a, b) result (c)
30 type(t1), intent(in) :: a, b
31 logical :: c
32 c = a%i == b%i
33 end function my_cmp
34 end module m
36 module m_os
37 implicit none
38 private :: t2
39 type t2
40 integer :: i
41 end type t2
42 interface operator (.eq.)
43 module procedure :: my_cmp
44 end interface
45 interface operator (.ne.)
46 module procedure :: my_cmp
47 end interface
48 interface operator (.le.)
49 module procedure :: my_cmp
50 end interface
51 interface operator (.lt.)
52 module procedure :: my_cmp
53 end interface
54 interface operator (.ge.)
55 module procedure :: my_cmp
56 end interface
57 interface operator (.gt.)
58 module procedure :: my_cmp
59 end interface
60 contains
61 elemental function my_cmp (a, b) result (c)
62 type(t2), intent(in) :: a, b
63 logical :: c
64 c = a%i .eq. b%i
65 end function my_cmp
66 end module m_os
68 ! new style only
69 module m1
70 use m, only: operator(==), operator(/=)
71 use m, only: operator(<=), operator(<)
72 use m, only: operator(>=), operator(>)
73 end module m1
75 ! old -> new style
76 module m2
77 use m_os, only: operator(==), operator(/=)
78 use m_os, only: operator(<=), operator(<)
79 use m_os, only: operator(>=), operator(>)
80 end module m2
82 ! new -> old style
83 module m3
84 use m, only: operator(.eq.), operator(.ne.)
85 use m, only: operator(.le.), operator(.lt.)
86 use m, only: operator(.ge.), operator(.gt.)
87 end module m3
89 ! old style only
90 module m4
91 use m_os, only: operator(.eq.), operator(.ne.)
92 use m_os, only: operator(.le.), operator(.lt.)
93 use m_os, only: operator(.ge.), operator(.gt.)
94 end module m4
96 ! new -> all styles
97 module m5
98 use m, only: operator(.eq.), operator(.ne.), operator(==), operator(/=)
99 use m, only: operator(.le.), operator(.lt.), operator(<=), operator(<)
100 use m, only: operator(.ge.), operator(.gt.), operator(>=), operator(>)
101 end module m5
103 ! old -> all styles
104 module m6
105 use m_os, only: operator(.eq.), operator(.ne.), operator(==), operator(/=)
106 use m_os, only: operator(.le.), operator(.lt.), operator(<=), operator(<)
107 use m_os, only: operator(.ge.), operator(.gt.), operator(>=), operator(>)
108 end module m6
110 ! all -> all styles
111 module m7
112 use m, only: operator(.eq.), operator(.ne.), operator(==), operator(/=)
113 use m, only: operator(.le.), operator(.lt.), operator(<=), operator(<)
114 use m, only: operator(.ge.), operator(.gt.), operator(>=), operator(>)
115 use m_os, only: operator(.eq.), operator(.ne.), operator(==), operator(/=)
116 use m_os, only: operator(.le.), operator(.lt.), operator(<=), operator(<)
117 use m_os, only: operator(.ge.), operator(.gt.), operator(>=), operator(>)
118 end module m7
120 module m_eq
121 implicit none
122 private :: t3
123 type t3
124 integer :: i
125 end type t3
126 interface operator (==)
127 module procedure :: my_cmp
128 end interface
129 contains
130 elemental function my_cmp (a, b) result (c)
131 type(t3), intent(in) :: a, b
132 logical :: c
133 c = a%i == b%i
134 end function my_cmp
135 end module m_eq
137 module m8
138 use m_eq, only: operator(==), operator(.eq.)
139 use m_eq, only: operator(/=) ! { dg-error "operator ./=. referenced" }
140 use m_eq, only: operator(.ne.) ! { dg-error "operator .\.ne\.. referenced" }
141 end module m8