Backport 00a05aea07 from trunk (fixing #3824).