bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#24863: Functions declared as side-effect-free do not generate warnin


From: Wilfred Hughes
Subject: bug#24863: Functions declared as side-effect-free do not generate warnings in the same file
Date: Wed, 2 Nov 2016 20:59:39 -0400

If I declare a function as side-effect-free, I do not get warnings
when I call it for side effects:

(defun foo-pure (x)
  (declare (side-effect-free t))
  x)

(defun foo-calls-pure ()
  ;; No warning here:
  (foo-pure 1)
  12)


However, if I define foo-pure in a standalone file and byte-compile
it, I get byte-compile warnings when I define foo-calls-pure in a
second file.

As mentioned in http://emacs.stackexchange.com/a/28341/304 , the
problem is that side-effect-free is added to the function symbol plist
at the wrong time. This can be worked around with:

(eval-and-compile (function-put 'foo-pure 'side-effect-free 't))

before defining foo-calls-pure.

However, ideally this wouldn't be required. I think it's just a matter
of changing defun-declarations-alist to:

   (list 'side-effect-free
         #'(lambda (f _args val)
             `(eval-and-compile (function-put ',f 'side-effect-free ',val)))
         "If non-nil, calls can be ignored if their value is unused.
If `error-free', drop calls even if `byte-compile-delete-errors' is nil.")





reply via email to

[Prev in Thread] Current Thread [Next in Thread]