Subject: bug#12813: gv-define-simple-setter can evaluate VAL more than once

From: Glenn Morris <[email-masked]>
Date: Tue, 06 Nov 2012 02:47:25 -0500

Package: emacs
Version: 24.2.50

I don't know if you will consider this a bug.
gv-define-simple-setter with FIX-RETURN non-nil evaluates VAL twice.
This may lead to unintended behaviour.

Artificial example in `emacs -Q':

(defun foo (x)
  (car x))

(defun foo-set (x y)
  (setcar x y))

(gv-define-simple-setter foo foo-set t)

(setq bar '(1 2 3))
(setq i 0)

(setf (foo bar) (setq i (1+ i)))   ; -> 1
bar                                ; -> (2 2 3) rather than (1 2 3)

defsetf in 24.2 was documented to not have this issue
(info "(cl)Customizing Setf")
[...]

(let ((temp VALUE))
  (UPDATE-FN ARG1 ARG2 ARG3 temp)
  temp)

So at the very least this will be relevant if http://debbugs.gnu.org/12812
gets the "obvious" fix.