I have c++ code that works properly in Debian (gcc (Debian 4.7.2-5) 4.7.2), but fails in Ubuntu (gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2). I'm getting stack space reused between variables, similar to what is described in these questions:
In C, do braces act as a stack frame?
except I'm not having nested scopes. Instead code looks similar to this:
TreeWalker walker;
walker.addVisitor(nodeType1, Visitor1());
walker.addVisitor(nodeType2, Visitor2());
...
walker.walkTree(tree);
I could mitigate this issue by allocating on the heap, but I'm wondering what can I do to make sure that local variables are left in place? Would assigning visitors to local variables be enough to ensure they won't be reused? Does standard provides any promise on the stack variables after their last use in function code?