For example, is the following code safe?
funcOp.walk([](Operation *op) {
doSomething();
if (condition)
op->erase();
});
Do I have to write like this?
SmallVector<Operation *> toRemove;
funcOp.walk([&](Operation *op) {
doSomething();
if (condition)
toRemove.push_back(op);
});
for (Operation *op : toRemove)
op->erase();
I know the second implementation is safer than the first one. But is it necessary to start erasing after the walk process finishes?
Thanks in advance!