The below code fragment (.ii attached) causes a segmentation fault. I can't see anything logically wrong with the code, but I am guessing an optimization of the pointers within "out" are causing the problem: a reallocation occurs in a deeper stack level, and the outer stack still maintains an old pointer.
However, since this code is logically valid, shouldn't it work, or shouldn't there are least be some way for it to work? Or, am I missing something obvious here. My first attempt was to mark "vector" volatile, but I then can't call any of its functions... -- #include <vector> using namespace std; unsigned append( unsigned count, vector<unsigned>& out ) { unsigned base = out.size(); unsigned need = count * 2; out.resize( base + need ); unsigned at = base; for( unsigned i = 0; i < count; i ++ ) { out.at(at++) = i; out.at(at++) = append( count-1, out ); } return base; } int main() { vector<unsigned> v; append( 50, v ); } -- g++ (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) Linux version 2.6.22-1-mepis64-smp ([EMAIL PROTECTED]) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) #1 SMP PREEMPT Mon Feb 18 23:03:02 EST 2008 -- Summary: using vector::resize within a recursive function causes a crash Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: eda-qa at disemia dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35594