Robert, thanks for your June 6 patch in Bug#31718#14. A small problem: gensym does not guarantee that the resulting symbol is unique, so the generated symbol could in theory appear in the input which would trigger the bug. Instead, let's use a guaranteed-unique object (cons nil nil). Also, I wrote a test case for this bug. I installed the attached patch into the master branch. Given the practical consequences of this bug I expect the bug fix should be backported into the emacs-26 branch too.