$cat reshape_bug.f90 program reshape_bug implicit none integer, parameter :: NX = 2 complex :: a(0:NX-1) a(:) = cmplx(0.0, 0.0) write(*,*) 'before' write(*,*) a(:) a(0:NX-1) = reshape(a(0:NX-1), (/NX/)) write(*,*) 'after' write(*,*) a(:) end program reshape_bug $gfortran-snapshot reshape_bug.f90 $./a.out before ( 0.000000 , 0.000000 ) ( 0.000000 , 0.000000 ) after ( 0.000000 , 0.000000 ) ( 2.022202 , 0.000000 ) The program changes the value of a(2) once reshape function is executed. But infact a(2) should just remain as ( 0.000000 , 0.000000 ). Using debian, sid. $gfortran-snapshot -v Using built-in specs. Target: i486-linux Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr/lib/gcc-snapshot --enable-shared --with-system-zlib --disable-nls --program-suffix=-20050507-1 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --enable-mpfr --disable-werror --disable-werror i486-linux Thread model: posix gcc version 4.1.0 20050507 (experimental)
Yes, there is a bug with reshape and complex numbers (PR21127). It should be fixed soon (a patch has been proposed). *** This bug has been marked as a duplicate of 21127 ***
Reopened, the bug is still present, and apparently completely unrelated to PR21127.
Confirmed.
Slightly reduced testcase: $ cat 21480.f90 program reshape_bug implicit none complex :: a(2), b(2) a = (/(1.0, -1.0), (2.0, -2.0)/) write(*,*) 'from' write(*,*) a b=reshape(a, shape(a)) write(*,*) 'to' write(*,*) b end program reshape_bug $ gfortran 21480.f90 $ ./a.out from ( 1.000000 , -1.000000 ) ( 2.000000 , -2.000000 ) to ( 1.000000 , -1.000000 ) ( 2.8025969E-45, 2.200292 ) In other words, this has nothing to do with arrays starting at 0.
Subject: Bug 21480 CVSROOT: /cvs/gcc Module name: gcc Changes by: tkoenig@gcc.gnu.org 2005-06-09 19:43:27 Modified files: libgfortran : ChangeLog libgfortran/m4 : reshape.m4 libgfortran/generated: reshape_c4.c reshape_c8.c reshape_i4.c reshape_i8.c gcc/testsuite : ChangeLog gcc/testsuite/gfortran.dg: reshape-complex.f90 Log message: 2005-06-09 Thomas Koenig <Thomas.Koenig@online.de> PR libfortran/21480 * m4/reshape.m4: Use sizeof (rtype_name) for sizes to be passed to reshape_packed. * generated/reshape_c4.c: Regenerated. * generated/reshape_c8.c: Regenerated. * generated/reshape_i4.c: Regenerated. * generated/reshape_i8.c: Regenerated. 2005-06-09 Thomas Koenig <Thomas.Koenig@online.de> PR libfortran/21480 * gfortran.dg/reshape-complex.f90: Add a test for a packed complex array. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.234&r2=1.235 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/m4/reshape.m4.diff?cvsroot=gcc&r1=1.9&r2=1.10 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_c4.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_c8.c.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i4.c.diff?cvsroot=gcc&r1=1.7&r2=1.8 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i8.c.diff?cvsroot=gcc&r1=1.7&r2=1.8 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5618&r2=1.5619 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/reshape-complex.f90.diff?cvsroot=gcc&r1=1.1&r2=1.2
Fixed in 4.1, waiting for 4.0 to reopen.
Subject: Bug 21480 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: tkoenig@gcc.gnu.org 2005-07-17 19:12:07 Modified files: libgfortran : ChangeLog libgfortran/generated: reshape_c4.c reshape_c8.c reshape_i4.c reshape_i8.c libgfortran/m4 : reshape.m4 gcc/testsuite : ChangeLog gcc/testsuite/gfortran.dg: reshape-complex.f90 Log message: 2005-07-17 Thomas Koenig <Thomas.Koenig@online.de> Backport from mainline. PR libfortran/21480 * m4/reshape.m4: Use sizeof (rtype_name) for sizes to be passed to reshape_packed. * generated/reshape_c4.c: Regenerated. * generated/reshape_c8.c: Regenerated. * generated/reshape_i4.c: Regenerated. * generated/reshape_i8.c: Regenerated. 2005-07-17 Thomas Koenig <Thomas.Koenig@online.de> Backport from mainline. PR libfortran/21480 * gfortran.dg/reshape-complex.f90: Add a test for a packed complex array. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.163.2.64&r2=1.163.2.65 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_c4.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1.2.3&r2=1.1.2.4 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_c8.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1.2.3&r2=1.1.2.4 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i4.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5.12.2&r2=1.5.12.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/generated/reshape_i8.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5.12.2&r2=1.5.12.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/m4/reshape.m4.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.6.12.3&r2=1.6.12.4 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.283&r2=1.5084.2.284 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/reshape-complex.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1.2.1&r2=1.1.2.2
Fixed in 4.0.