When an ifstream object is used in several open()-close() cycles, it seems to remember past cycles in the Red Hat gcc version.
STEPS TO REPRODUCE: 1) Compile the attached code using gcc version 4.1.0 20060515 (Red Hat 4.1.0-18) 2) Compile the attached code using gcc version 4.0.2 3) Create a file named "filetest.mat" in the directory where you exectude the binaries 4) Compare the results: They are different ACTUAL RESULTS: (Output from program compiled with gcc 4.1.0 20060515 (Red Hat 4.1.0-18)) ------------------------------------------------------ Try 1: ifstream-declaration outside loop (not working) could not open file ./not_existing_directory/filetest.mat could not open file ./filetest.mat ------------------------------------------------------ Try 2: ifstream-declaration inside loop (working) could not open file ./not_existing_directory/filetest.mat could open file ./filetest.mat ------------------------------------------------------ EXPECTED RESULTS: (Output from program compiled with gcc 4.0.2) ------------------------------------------------------ Try 1: ifstream-declaration outside loop (not working) could not open file ./not_existing_directory/filetest.mat could open file ./filetest.mat ------------------------------------------------------ Try 2: ifstream-declaration inside loop (working) could not open file ./not_existing_directory/filetest.mat could open file ./filetest.mat ------------------------------------------------------ BUILD INFOS: Faulty version: --------------- gcc version 4.1.0 20060515 (Red Hat 4.1.0-18) Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --with-gxx-include-dir=/usr/include/c++/3.4.3 --enable-libgcj-multifile --enable-languages=c,c++,java,f95 --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux Thread model: posix Working version: ---------------- gcc version 4.0.2 Reading specs from /usr/pack/gcc-4.0.2-mo/amd64-debian-linux3.1/lib/gcc/x86_64-unknown-linux-gnu/4.0.2/specs Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/usr/pack/gcc-4.0.2-mo --exec-prefix=/usr/pack/gcc-4.0.2-mo/amd64-debian-linux3.1 --with-gxx-include-dir=/usr/pack/gcc-4.0.2-mo/include/c++ --disable-nls --enable-languages=c,c++,f95 Thread model: posix -- Summary: Ifstream bug using Red Hat g++-4.1.0 compared to g++- 4.0.2 Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: steigers at phys dot ethz dot ch http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30711