Merge from trunk.  Fixes #9031