1! RUN: %S/test_errors.sh %s %t %f18
2! Test restrictions on what subprograms can be used for defined operators.
3! See: 15.4.3.4.2
4
5module m1
6  interface operator(+)
7    !ERROR: OPERATOR(+) procedure 'add1' must be a function
8    subroutine add1(x, y, z)
9      real, intent(out) :: x
10      real, intent(in) :: y, z
11    end
12  end interface
13end
14
15module m2
16  interface operator(-)
17    real function sub1(x)
18      logical, intent(in) :: x
19    end
20    real function sub2(x, y)
21      logical, intent(in) :: x, y
22    end
23    !ERROR: OPERATOR(-) function 'sub3' must have one or two dummy arguments
24    real function sub3(x, y, z)
25      real, intent(in) :: x, y, z
26    end
27  end interface
28  interface operator(.not.)
29    !ERROR: OPERATOR(.NOT.) function 'not1' must have one dummy argument
30    real function not1(x, y)
31      real, intent(in) :: x, y
32    end
33  end interface
34end
35
36module m3
37  interface operator(/)
38    !ERROR: OPERATOR(/) function 'divide' may not have assumed-length CHARACTER(*) result
39    character(*) function divide(x, y)
40      character(*), intent(in) :: x, y
41    end
42  end interface
43  interface operator(<)
44    !ERROR: In OPERATOR(<) function 'lt1', dummy argument 'x' must have INTENT(IN) or VALUE attribute
45    !ERROR: In OPERATOR(<) function 'lt1', dummy argument 'y' may not be OPTIONAL
46    logical function lt1(x, y)
47      logical :: x
48      real, value, optional :: y
49    end
50    !ERROR: In OPERATOR(<) function 'lt2', dummy argument 'y' must be a data object
51    logical function lt2(x, y)
52      logical, intent(in) :: x
53      intent(in) :: y
54      interface
55        subroutine y()
56        end
57      end interface
58    end
59  end interface
60end
61
62module m4
63  interface operator(+)
64    !ERROR: OPERATOR(+) function 'add' conflicts with intrinsic operator
65    complex function add(x, y)
66      real, intent(in) :: x
67      integer, value :: y
68    end
69    !ERROR: OPERATOR(+) function 'plus' conflicts with intrinsic operator
70    real function plus(x)
71      complex, intent(in) :: x
72    end
73  end interface
74  interface operator(.not.)
75    real function not1(x)
76      real, value :: x
77    end
78    !ERROR: OPERATOR(.NOT.) function 'not2' conflicts with intrinsic operator
79    logical(8) function not2(x)
80      logical(8), value :: x
81    end
82  end interface
83  interface operator(.and.)
84    !ERROR: OPERATOR(.AND.) function 'and' conflicts with intrinsic operator
85    real function and(x, y)
86      logical(1), value :: x
87      logical(8), value :: y
88    end
89  end interface
90  interface operator(//)
91    real function concat1(x, y)
92      real, value :: x, y
93    end
94    real function concat2(x, y)
95      character(kind=1, len=4), intent(in) :: x
96      character(kind=4, len=4), intent(in) :: y
97    end
98    !ERROR: OPERATOR(//) function 'concat3' conflicts with intrinsic operator
99    real function concat3(x, y)
100      character(kind=4, len=4), intent(in) :: x
101      character(kind=4, len=4), intent(in) :: y
102    end
103  end interface
104end
105