Issue #5983: merge -x code

merge -x #8851
merge -x #8804