1! { dg-do compile } 2! PR fortran/65454 - accept both old and new-style relational operators 3 4module 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 28contains 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 34end module m 35 36module 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 60contains 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 66end module m_os 67 68! new style only 69module m1 70 use m, only: operator(==), operator(/=) 71 use m, only: operator(<=), operator(<) 72 use m, only: operator(>=), operator(>) 73end module m1 74 75! old -> new style 76module m2 77 use m_os, only: operator(==), operator(/=) 78 use m_os, only: operator(<=), operator(<) 79 use m_os, only: operator(>=), operator(>) 80end module m2 81 82! new -> old style 83module 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.) 87end module m3 88 89! old style only 90module 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.) 94end module m4 95 96! new -> all styles 97module 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(>) 101end module m5 102 103! old -> all styles 104module 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(>) 108end module m6 109 110! all -> all styles 111module 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(>) 118end module m7 119 120module 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 129contains 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 135end module m_eq 136 137module 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" } 141end module m8 142