124 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Test restrictions on what subprograms can be used for defined operators.3! See: 15.4.3.4.24 5module m16 interface operator(+)7 !ERROR: OPERATOR(+) procedure 'add1' must be a function8 subroutine add1(x, y, z)9 real, intent(out) :: x10 real, intent(in) :: y, z11 end12 end interface13end14 15module m216 interface operator(-)17 real function sub1(x)18 logical, intent(in) :: x19 end20 real function sub2(x, y)21 logical, intent(in) :: x, y22 end23 !ERROR: OPERATOR(-) function 'sub3' must have one or two dummy arguments24 real function sub3(x, y, z)25 real, intent(in) :: x, y, z26 end27 end interface28 interface operator(.not.)29 !ERROR: OPERATOR(.NOT.) function 'not1' must have one dummy argument30 real function not1(x, y)31 real, intent(in) :: x, y32 end33 end interface34end35 36module m337 interface operator(/)38 !ERROR: A function interface may not declare an assumed-length CHARACTER(*) result39 character(*) function divide(x, y)40 character(*), intent(in) :: x, y41 end42 end interface43 interface operator(<)44 !WARNING: In OPERATOR(<) function 'lt1', dummy argument 'x' should have INTENT(IN) or VALUE attribute [-Wdefined-operator-args]45 !ERROR: In OPERATOR(<) function 'lt1', dummy argument 'y' may not be OPTIONAL46 logical function lt1(x, y)47 logical :: x48 real, value, optional :: y49 end50 !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 object52 logical function lt2(x, y)53 logical, intent(out) :: x54 intent(in) :: y55 interface56 subroutine y()57 end58 end interface59 end60 end interface61 contains62 subroutine s(alcf1, alcf2)63 interface64 character(*) function alcf1(x, y)65 character(*), intent(in) :: x, y66 end function67 character(*) function alcf2(x, y)68 character(*), intent(in) :: x, y69 end function70 end interface71 interface operator(+)72 !ERROR: OPERATOR(+) function 'alcf1' may not have assumed-length CHARACTER(*) result73 procedure alcf174 end interface75 !ERROR: OPERATOR(-) function 'alcf2' may not have assumed-length CHARACTER(*) result76 generic :: operator(-) => alcf277 end subroutine78end79 80module m481 interface operator(+)82 !ERROR: OPERATOR(+) function 'add' conflicts with intrinsic operator83 complex function add(x, y)84 real, intent(in) :: x85 integer, value :: y86 end87 !ERROR: OPERATOR(+) function 'plus' conflicts with intrinsic operator88 real function plus(x)89 complex, intent(in) :: x90 end91 end interface92 interface operator(.not.)93 !WARNING: The external interface 'not1' is not compatible with an earlier definition (distinct numbers of dummy arguments) [-Wexternal-interface-mismatch]94 real function not1(x)95 real, value :: x96 end97 !ERROR: OPERATOR(.NOT.) function 'not2' conflicts with intrinsic operator98 logical(8) function not2(x)99 logical(8), value :: x100 end101 end interface102 interface operator(.and.)103 !ERROR: OPERATOR(.AND.) function 'and' conflicts with intrinsic operator104 real function and(x, y)105 logical(1), value :: x106 logical(8), value :: y107 end108 end interface109 interface operator(//)110 real function concat1(x, y)111 real, value :: x, y112 end113 real function concat2(x, y)114 character(kind=1, len=4), intent(in) :: x115 character(kind=4, len=4), intent(in) :: y116 end117 !ERROR: OPERATOR(//) function 'concat3' conflicts with intrinsic operator118 real function concat3(x, y)119 character(kind=4, len=4), intent(in) :: x120 character(kind=4, len=4), intent(in) :: y121 end122 end interface123end124