I think I found a bug related to operator overloading in gfortran-4.1.0 (as
you can see below gfortran-4.2.0 doesn't seem to have the problem).

The problem arises when trying to perform an operation which takes
a multidimensional array and two operators are defined:

    - One with two multidimensional arguments.
    - Another with a single unidimensional argument and another
      multimensional argument.

One would expect the first one being applied when both arguments have more
than one dimension, but version 4.1.0 keeps using the second operator.

A small example is attached below, as well as compiler output for both 4.1
and 4.2 versions of the compiler.

This bug is reproducible also in powerpc-unknown-linux-gnu box.

Compiling command:
------------------

<[EMAIL PROTECTED]> [~/bug]$ gfortran -v -save-temps -o bugs bug.f90 
Driving: gfortran -v -save-temps -o bugs bug.f90 -lgfortranbegin -lgfortran -lm
-shared-libgcc
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/gcc-4.1.0/work/gcc-4.1.0/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.0
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.0
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.0/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.0/info
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/include/g++-v4
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--disable-nls --with-system-zlib --disable-checking --disable-werror
--disable-libunwind-exceptions --disable-multilib --disable-libmudflap
--disable-libssp --disable-libgcj --enable-languages=c,c++,fortran
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu
Thread model: posix
gcc version 4.1.0 (Gentoo 4.1.0)
 /usr/libexec/gcc/i686-pc-linux-gnu/4.1.0/f951 bug.f90 -quiet -dumpbase bug.f90
-mtune=pentiumpro -auxbase bug -version -o bug.s
GNU F95 version 4.1.0 (Gentoo 4.1.0) (i686-pc-linux-gnu)
        compiled by GNU C version 4.1.0 (Gentoo 4.1.0).
GGC heuristics: --param ggc-min-expand=63 --param ggc-min-heapsize=62387
 /usr/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../../i686-pc-linux-gnu/bin/as -V
-Qy -o bug.o bug.s
GNU assembler version 2.16.1 (i686-pc-linux-gnu) using BFD version 2.16.1
 /usr/libexec/gcc/i686-pc-linux-gnu/4.1.0/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o bugs
/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../crt1.o
/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../crti.o
/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/crtbegin.o
-L/usr/lib/gcc/i686-pc-linux-gnu/4.1.0 -L/usr/lib/gcc/i686-pc-linux-gnu/4.1.0
-L/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../../i686-pc-linux-gnu/lib
-L/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/../../.. bug.o -lgfortranbegin
-lgfortran -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/crtend.o
/usr/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../crtn.o

Execution command:
------------------

<[EMAIL PROTECTED]> [~/bug]$ ./bugs 
 Stinks! I do not want this!
           1           1

The code runs over the non-two dimensional argument function.

Source code
-----------

module bug_mod

    implicit none

    type foo
        integer :: bar
    end type foo

    interface operator (+)
        module procedure fun, sux
    end interface


    contains

        function fun ( x, y ) result (z)
            type(foo), intent(in), dimension(:,:) :: x
            type(foo), intent(in), dimension(size(x,1),size(x,2)):: y
            type(foo),             dimension(size(x,1),size(x,2)):: z;

            print*,'I want to run this function'
            z%bar = 0
        end function fun

        function sux( x, y ) result (z)
            type(foo), intent(in), dimension(:,:)       :: x
            type(foo), intent(in), dimension(size(x,1)) :: y
            type(foo),             dimension(size(x,1)) :: z

            print*,'Stinks! I do not want this!'
            z%bar = 1
        end function sux


end module bug_mod

program bug

    use bug_mod
    implicit none

    type(foo), dimension(2,2) :: a,c

    a%bar = 0
    c%bar = 0

    print*, (a + c) ! I would expect dim(2) + dim(2) => fun

end program bug


-- 
           Summary: Bad overloaded operator selected
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ajdiaz at connectical dot net
 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=27401

Reply via email to