1! RUN: %python %S/test_errors.py %s %flang_fc1 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: A function interface may not declare an 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 !WARNING: In OPERATOR(<) function 'lt1', dummy argument 'x' should 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 'x' may not be INTENT(OUT) 51 !ERROR: In OPERATOR(<) function 'lt2', dummy argument 'y' must be a data object 52 logical function lt2(x, y) 53 logical, intent(out) :: x 54 intent(in) :: y 55 interface 56 subroutine y() 57 end 58 end interface 59 end 60 end interface 61 contains 62 subroutine s(alcf1, alcf2) 63 interface 64 character(*) function alcf1(x, y) 65 character(*), intent(in) :: x, y 66 end function 67 character(*) function alcf2(x, y) 68 character(*), intent(in) :: x, y 69 end function 70 end interface 71 interface operator(+) 72 !ERROR: OPERATOR(+) function 'alcf1' may not have assumed-length CHARACTER(*) result 73 procedure alcf1 74 end interface 75 !ERROR: OPERATOR(-) function 'alcf2' may not have assumed-length CHARACTER(*) result 76 generic :: operator(-) => alcf2 77 end subroutine 78end 79 80module m4 81 interface operator(+) 82 !ERROR: OPERATOR(+) function 'add' conflicts with intrinsic operator 83 complex function add(x, y) 84 real, intent(in) :: x 85 integer, value :: y 86 end 87 !ERROR: OPERATOR(+) function 'plus' conflicts with intrinsic operator 88 real function plus(x) 89 complex, intent(in) :: x 90 end 91 end interface 92 interface operator(.not.) 93 !WARNING: The external interface 'not1' is not compatible with an earlier definition (distinct numbers of dummy arguments) 94 real function not1(x) 95 real, value :: x 96 end 97 !ERROR: OPERATOR(.NOT.) function 'not2' conflicts with intrinsic operator 98 logical(8) function not2(x) 99 logical(8), value :: x 100 end 101 end interface 102 interface operator(.and.) 103 !ERROR: OPERATOR(.AND.) function 'and' conflicts with intrinsic operator 104 real function and(x, y) 105 logical(1), value :: x 106 logical(8), value :: y 107 end 108 end interface 109 interface operator(//) 110 real function concat1(x, y) 111 real, value :: x, y 112 end 113 real function concat2(x, y) 114 character(kind=1, len=4), intent(in) :: x 115 character(kind=4, len=4), intent(in) :: y 116 end 117 !ERROR: OPERATOR(//) function 'concat3' conflicts with intrinsic operator 118 real function concat3(x, y) 119 character(kind=4, len=4), intent(in) :: x 120 character(kind=4, len=4), intent(in) :: y 121 end 122 end interface 123end 124