Subject: Re: bug#72313: 31.0.50; Warning about cl-member possibly being undefined when using cl-pushnew

From: Tassilo Horn <[email-masked]>
Date: Sat, 27 Jul 2024 09:13:50 +0200

Stefan Monnier <[email-masked]> writes:

Hi Stefan,

>     (macroexpand-all '(cl-pushnew (list 1 2 3) s :test (lambda (_a _b) nil)))
> =>
>     (setq s
>      (let* ((va (list 1 2 3)))
>        (if (cl-member va s :test #'(lambda (_a _b) nil)) s (cons va s))))
>
>> My assumption is that (eval-when-compile (require 'cl-lib)) should be
>> fine when using only macros from cl-lib which in turn should expand
>> to cl-free code,
>
> That's not the case here (and a few other places).  In the past, I've
> moved some of this kind of code to `cl-preloaded`, so as to make
> things easier for programmers (to avoid them having to know which CL
> macros emit code which calls CL functions (and when)), but there are
> still cases like above, yes.

So the conclusion is to simply (require 'cl-lib) instead of
(eval-when-compile (require 'cl-lib))?  But how can the byte-compiler
conclude that cl-member might not be defined at runtime given that it's
an autoloaded function?

Addon question: should a package list cl-lib in Package-Requires if it
already requires an Emacs version where a good-enough cl-lib is included
anyway?

Thanks,
  Tassilo