It took me a long time to whittle this down to a small example, but here it is:
#include <iostream> #include <deque> #include <memory> using std::deque; using std::auto_ptr; struct A { long x; char y; A() : x(0) {} }; auto_ptr<deque<A> > foo(int l){ auto_ptr<deque<A> > d(new deque<A>); A a, b, c; for (int i=0; i<l; i++) d->push_back(a); return d; } int main(int argc, char **argv) { auto_ptr<deque<A> > d = foo(atoi(argv[1])); A a, b, c; for (deque<A>::iterator i = d->begin(); i != d->end(); i++) { std::cerr << (*i).x << std::endl; } return 0; } $ /work/external/wwc/bin/g++-3.4.4 -v -save-temps -Wall -fno-strict-aliasing -O2 /work/nova/6067/src/foo.C Reading specs from /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/specs Configured with: ../gcc-3.4.4/configure --prefix=/work/external/wwc/prgcc --program-suffix=-3.4.4 --enable-threads --with-included-gettext --enable-languages=c,c++,f77 --with-gnu-as --with-as=/work/external/wwc/prodbinu216/bin/as --with-gnu-ld --with-ld=/work/external/wwc/prodbinu216/bin/ld : (reconfigured) ../gcc-3.4.4/configure --prefix=/work/external/wwc/prgcc --program-suffix=-3.4.4 --enable-threads --with-included-gettext --enable-languages=c,c++,f77 --with-gnu-as --with-as=/work/external/wwc/prodbinu216/bin/as --with-gnu-ld --with-ld=/work/external/wwc/prodbinu216/bin/ld Thread model: posix gcc version 3.4.4 /work/external/wwc/prgcc/libexec/gcc/sparc-sun-solaris2.8/3.4.4/cc1plus -E -quiet -v /work/nova/6067/src/foo.C -mcpu=v7 -Wall -fno-strict-aliasing -O2 -o foo.ii ignoring nonexistent directory "/work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/../../../../sparc-sun-solaris2.8/include" #include "..." search starts here: #include <...> search starts here: /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/../../../../include/c++/3.4.4 /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/../../../../include/c++/3.4.4/sparc-sun-solaris2.8 /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/../../../../include/c++/3.4.4/backward /usr/local/include /work/external/wwc/prgcc/include /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/include /usr/include End of search list. /work/external/wwc/prgcc/libexec/gcc/sparc-sun-solaris2.8/3.4.4/cc1plus -fpreprocessed foo.ii -quiet -dumpbase foo.C -mcpu=v7 -auxbase foo -O2 -Wall -version -fno-strict-aliasing -o foo.s GNU C++ version 3.4.4 (sparc-sun-solaris2.8) compiled by GNU C version 3.4.4. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 /work/external/wwc/prodbinu216/bin/as --traditional-format -V -Qy -s -xarch=v8 -o foo.o foo.s GNU assembler version 2.16 (sparc-sun-solaris2.8) using BFD version 2.16 /work/external/wwc/prgcc/libexec/gcc/sparc-sun-solaris2.8/3.4.4/collect2 -V -Y P,/usr/ccs/lib:/usr/lib -rpath-link /usr/lib -Qy /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/crt1.o /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/crti.o /usr/ccs/lib/values-Xa.o /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/crtbegin.o -L/work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4 -L/usr/ccs/bin -L/usr/ccs/lib -L/work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/../../.. foo.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc -lc /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/crtend.o /work/external/wwc/prgcc/lib/gcc/sparc-sun-solaris2.8/3.4.4/crtn.o GNU ld version 2.16 Supported emulations: elf32_sparc elf64_sparc $ If I run this program with the argument greater than 64, it prints out 63 zeros, followed by the number 513, followed by more zeros. If I run it with the argument 64, it does the same and then SEGVs. This is as simple an example as I can produce. The following simplifications cause the program to behave properly: 1. removing the auto_ptr 2. removing the -fno-strict-aliasing 3. removing any of the unused local variables 4. moving the code from foo() into main 5. making the iterator a const_iterator 6. using -fno-unit-at-a-time 7. replacing -O2 with -O1 Please let me know if you need any more information. -- David Magerman [EMAIL PROTECTED] -- Summary: Corrupted memory with deque of >63 items under gcc-3.4.4 Product: gcc Version: 3.4.4 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: magerman at rentec dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: sparc-sun-solaris2.8 GCC host triplet: sparc-sun-solaris2.8 GCC target triplet: sparc-sun-solaris2.8 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21939