1! { dg-do compile } 2! { dg-options "-std=legacy" } 3! Tests the fix for PR27122, in which the requirements of 12.3.2.1.1 4! for defined operators were not enforced. 5! 6! Based on PR test by Thomas Koenig <tkoenig@gcc.gnu.org> 7! 8module mymod 9 interface operator (.foo.) 10 module procedure foo_0 11 module procedure foo_1 12 module procedure foo_2 13 module procedure foo_3 14 module procedure foo_1_OK ! { dg-error "Ambiguous interfaces" } 15 module procedure foo_2_OK 16 function foo_chr (chr) ! { dg-error "cannot be assumed character length" } 17 character(*) :: foo_chr 18 character(*), intent(in) :: chr 19 end function foo_chr 20 end interface 21 22 ! 23 ! PR fortran/33117 24 ! PR fortran/46478 25 ! Mixing FUNCTIONs and SUBROUTINEs in an INTERFACE hides the 26 ! errors that should be tested here. Hence split out subroutine 27 ! to test separately. 28 ! 29 interface operator (.bar.) 30 subroutine bad_foo (chr) ! { dg-error "must be a FUNCTION" } 31 character(*), intent(in) :: chr 32 end subroutine bad_foo 33 end interface 34 35contains 36 function foo_0 () ! { dg-error "must have at least one argument" } 37 integer :: foo_1 38 foo_0 = 1 39 end function foo_0 40 function foo_1 (a) ! { dg-error "must be INTENT" } 41 integer :: foo_1 42 integer :: a 43 foo_1 = 1 44 end function foo_1 45 function foo_1_OK (a) 46 integer :: foo_1_OK 47 integer, intent (in) :: a 48 foo_1_OK = 1 49 end function foo_1_OK 50 function foo_2 (a, b) ! { dg-error "cannot be optional" } 51 integer :: foo_2 52 integer, intent(in) :: a 53 integer, intent(in), optional :: b 54 foo_2 = 2 * a + b 55 end function foo_2 56 function foo_2_OK (a, b) 57 real :: foo_2_OK 58 real, intent(in) :: a 59 real, intent(in) :: b 60 foo_2_OK = 2.0 * a + b 61 end function foo_2_OK 62 function foo_3 (a, b, c) ! { dg-error "must have, at most, two arguments" } 63 integer :: foo_3 64 integer, intent(in) :: a, b, c 65 foo_3 = a + 3 * b - c 66 end function foo_3 67end module mymod 68