summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/operator_4.f90
blob: 39cd7ebdf01e28585b6303e9eb37c9f26bec56bf (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
! PR 17711 : Verify error message text meets operator in source
! { dg-do compile }

MODULE mod_t
  type :: t
    integer :: x
  end type

  INTERFACE OPERATOR(==)
    MODULE PROCEDURE t_eq
  END INTERFACE

  INTERFACE OPERATOR(/=)
    MODULE PROCEDURE t_ne
  END INTERFACE

  INTERFACE OPERATOR(>)
    MODULE PROCEDURE t_gt
  END INTERFACE

  INTERFACE OPERATOR(>=)
    MODULE PROCEDURE t_ge
  END INTERFACE

  INTERFACE OPERATOR(<)
    MODULE PROCEDURE t_lt
  END INTERFACE

  INTERFACE OPERATOR(<=)
    MODULE PROCEDURE t_le
  END INTERFACE

CONTAINS
  LOGICAL FUNCTION t_eq(this, other)
    TYPE(t), INTENT(in) :: this, other
    t_eq = (this%x == other%x)
  END FUNCTION

  LOGICAL FUNCTION t_ne(this, other)
    TYPE(t), INTENT(in) :: this, other
    t_ne = (this%x /= other%x)
  END FUNCTION

  LOGICAL FUNCTION t_gt(this, other)
    TYPE(t), INTENT(in) :: this, other
    t_gt = (this%x > other%x)
  END FUNCTION

  LOGICAL FUNCTION t_ge(this, other)
    TYPE(t), INTENT(in) :: this, other
    t_ge = (this%x >= other%x)
  END FUNCTION

  LOGICAL FUNCTION t_lt(this, other)
    TYPE(t), INTENT(in) :: this, other
    t_lt = (this%x < other%x)
  END FUNCTION

  LOGICAL FUNCTION t_le(this, other)
    TYPE(t), INTENT(in) :: this, other
    t_le = (this%x <= other%x)
  END FUNCTION
END MODULE

PROGRAM pr17711
  USE mod_t

  LOGICAL :: A
  INTEGER :: B
  TYPE(t) :: C

  A = (A == B)   ! { dg-error "comparison operator '=='" }
  A = (A.EQ.B)   ! { dg-error "comparison operator '.eq.'" }
  A = (A /= B)   ! { dg-error "comparison operator '/='" }
  A = (A.NE.B)   ! { dg-error "comparison operator '.ne.'" }
  A = (A <= B)   ! { dg-error "comparison operator '<='" }
  A = (A.LE.B)   ! { dg-error "comparison operator '.le.'" }
  A = (A <  B)   ! { dg-error "comparison operator '<'" }
  A = (A.LT.B)   ! { dg-error "comparison operator '.lt.'" }
  A = (A >= B)   ! { dg-error "comparison operator '>='" }
  A = (A.GE.B)   ! { dg-error "comparison operator '.ge.'" }
  A = (A >  B)   ! { dg-error "comparison operator '>'" }
  A = (A.GT.B)   ! { dg-error "comparison operator '.gt.'" }

  ! this should also work with user defined operators
  A = (A == C)   ! { dg-error "comparison operator '=='" }
  A = (A.EQ.C)   ! { dg-error "comparison operator '.eq.'" }
  A = (A /= C)   ! { dg-error "comparison operator '/='" }
  A = (A.NE.C)   ! { dg-error "comparison operator '.ne.'" }
  A = (A <= C)   ! { dg-error "comparison operator '<='" }
  A = (A.LE.C)   ! { dg-error "comparison operator '.le.'" }
  A = (A <  C)   ! { dg-error "comparison operator '<'" }
  A = (A.LT.C)   ! { dg-error "comparison operator '.lt.'" }
  A = (A >= C)   ! { dg-error "comparison operator '>='" }
  A = (A.GE.C)   ! { dg-error "comparison operator '.ge.'" }
  A = (A >  C)   ! { dg-error "comparison operator '>'" }
  A = (A.GT.C)   ! { dg-error "comparison operator '.gt.'" }
END PROGRAM

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