This RAII class can help to undo tentative insn changes on failure.
When an object of the class goes out of scope, it undoes all group
changes that have been made via the validate_change machinery and
not yet confirmed via confirm_change_group.
For example:
insn_change_watermark watermark;
validate_change (..., true); // A
...
if (test)
// Undoes change A.
return false;
...
validate_change (..., true); // B
...
if (test)
// Undoes changes A and B.
return false;
...
confirm_change_group ();
Code that wants to avoid this behavior can use keep ():
insn_change_watermark watermark;
validate_change (..., true); // A
...
if (test)
// Undoes change A.
return false;
...
watermark.keep ();
validate_change (..., true); // B
...
if (test)
// Undoes change B, but not A.
return false;
...
confirm_change_group ();