Binary operator functions require their arguments to have intent(in).
Gfortran currently doesn't enforce this, ifort does.

$ cat oper-fun.f90
module mymod
  interface operator (.foo.)
     module procedure foo_int
  end interface
contains
  function foo_int (a, b)
    integer:: foo_int
    integer :: a, b    ! <==== should be intent(in) here
    foo_int = a + 3 * b
  end function foo_int
end module mymod

program main
  use mymod
  print *, 1 .foo. 2
end program main
$ gfortran oper-fun.f90 && ./a.out
           7
$ ifort oper-fun.f90
fortcom: Error: oper-fun.f90, line 6: An explicit INTENT(IN) declaration is
expected for this dummy argument of the defined operation.   [A]
  function foo_int (a, b)
--------------------^
fortcom: Error: oper-fun.f90, line 6: An explicit INTENT(IN) declaration is
expected for this dummy argument of the defined operation.   [B]
  function foo_int (a, b)
-----------------------^
fortcom: Error: oper-fun.f90, line 14: Error in opening the Library module
file.   [MYMOD]
  use mymod
------^
fortcom: Error: oper-fun.f90, line 15: Dotted string neither a defined operator
nor a structure component   [FOO]
  print *, 1 .foo. 2
--------------^
compilation aborted for oper-fun.f90 (code 1)


-- 
           Summary: binary operator functions should require intent(in)
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27122

Reply via email to