public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/25396]  New: Operator overloading for array-valued functions gets shape incorrectly
@ 2005-12-13 17:56 jb at gcc dot gnu dot org
  2005-12-27 19:26 ` [Bug fortran/25396] " eedelman at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jb at gcc dot gnu dot org @ 2005-12-13 17:56 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-12-31 16:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-13 17:56 [Bug fortran/25396] New: Operator overloading for array-valued functions gets shape incorrectly jb at gcc dot gnu dot org
2005-12-27 19:26 ` [Bug fortran/25396] " eedelman at gcc dot gnu dot org
2005-12-29 20:01 ` eedelman at gcc dot gnu dot org
2005-12-29 20:57 ` eedelman at gcc dot gnu dot org
2005-12-30 15:02 ` eedelman at gcc dot gnu dot org
2005-12-30 15:07 ` eedelman at gcc dot gnu dot org
2005-12-30 15:11 ` eedelman at gcc dot gnu dot org
2005-12-31 16:39 ` tobi at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).