Consider the following testcase:
module geometry
implicit none
interface operator(.cross.)
module procedure cross
end interface
contains
! Cross product between two 3d vectors.
pure function cross(a, b)
real, dimension(3), intent(in) :: a,b
real, dimension(3) :: cross
cross = (/ a(2) * b(3) - a(3) * b(2), &
a(3) * b(1) - a(1) * b(3), &
a(1) * b(2) - a(2) * b(1) /)
end function cross
end module geometry
program opshape
use geometry
implicit none
real :: t(3,3), a(3), b(3)
! Storing to an array works.
b = t(:,2) .cross. t(:,3)
! However, when the result is not stored it doesn't work.
! Following two line are equivalent, but the first one causes an
! error.
print *, size (t(:,2) .cross. t(:,3))
print *, size (cross (t(:,2), t(:,3)))
! Same here.
a = dot_product (t(:,1), t(:,2) .cross. t(:,3))
a = dot_product (t(:,1), cross (t(:,2), t(:,3)))
end program opshape
The two dot_product and the two size invocations are equivalent, but the ones
that use the operator .cross. instead of calling the cross function directly,
cause errors:
~/src/gfortran/test/opshape% gfortran opshape.f90
In file opshape.f90:37
print *, size (t(:,2) .cross. t(:,3))
1
Error: 'array' argument of 'size' intrinsic at (1) must be an array
In file opshape.f90:41
a = dot_product (t(:,1), t(:,2) .cross. t(:,3))
1
Error: 'vector_b' argument of 'dot_product' intrinsic at (1) must be of rank 1
--
Summary: Operator overloading for array-valued functions gets
shape incorrectly
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jb at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25396