Subject: bug#55413: 29.0.50; False positives in check-declare-directory

From: Eli Zaretskii <[email-masked]>
Date: Sat, 14 May 2022 19:33:56 +0300

When 'check-declare-directory' is run on the 'lisp sub-directory of
the Emacs source tree, it produces quite a few false positives for
some advanced uses of Emacs Lisp.  Below are examples of the
problematic warnings and the Lisp code which triggers them:

  cedet/semantic/wisent/comp.el:68:Warning (check-declare): said ‘unknown
      function’ was defined in unknown file: Malformed declaration

This is because the function was declared inside eval-when-compile:

  (eval-when-compile
    (defun wisent-context-name (name)   <<<<<<<<<<<<<<<<<<<<<<<
      "Return the context name from NAME."
      (if (and name (symbolp name))
	  (intern (format "wisent-context-%s" name))
	(error "Invalid context name: %S" name)))

  (defmacro wisent-defcontext (name &rest vars)
    "Define a context NAME that will bind variables VARS."
    (declare (indent 1))
    (declare-function wisent-context-name nil (name))  <<<<<<<<<<<<<<

  progmodes/elisp-mode.el:779:Warning (check-declare): said ‘xref-make’ was
      defined in progmodes/xref.el: function not found

This is because xref-make is a constructor:

  (xref--defstruct (xref-item
		    (:constructor xref-make (summary location))  <<<<<<<<
		    (:noinline t))
    "An xref item describes a reference to a location somewhere."
    (summary nil :documentation "String which describes the location.

  comint.el:4029:Warning (check-declare): said ‘url-host’ was defined in
      url/url-parse.el: function not found Disable showing Disable logging

This is because url-host "has a compiler macro".

  autoinsert.el:92:Warning (check-declare): said ‘sgml-tag’ was defined in
      textmodes/sgml-mode.el: function not found

This is because sgml-tag is defined via define-skeleton.

  progmodes/gud.el:62:Warning (check-declare): said ‘gud-statement’ was defined
      in progmodes/gud.el: function not found

This is because gud-statement is defined via gud-def:

  (gud-def gud-statement "!%e"      "\C-e" "Execute Python statement at point.")

  obsolete/cust-print.el:240:Warning (check-declare): said
      ‘cust-print-original-format’ was defined in obsolete/cust-print.el:
      function not found

This is because cust-print-original-format is defined like this:

  ;; Save emacs routines.
  (if (not (fboundp 'cust-print-original-prin1))
      (mapc #'cust-print-set-function-cell
	    '((cust-print-original-prin1 prin1)
	      (cust-print-original-princ princ)
	      (cust-print-original-print print)
	      (cust-print-original-prin1-to-string prin1-to-string)
	      (cust-print-original-format format)  <<<<<<<<<<<<<<<<<<<<
	      (cust-print-original-message message)
	      (cust-print-original-error error))))

  net/sieve.el:107:Warning (check-declare): said ‘sieve-manage-mode-menu’ was
      defined in net/sieve.el: function not found

This is because sieve-manage-mode-menu is defined via easy-menu-define:

  (easy-menu-define sieve-manage-mode-menu sieve-manage-mode-map
    "Sieve Menu."
    '("Manage Sieve"
      ["Edit script" sieve-edit-script t]

  mail/rmail.el:227:Warning (check-declare): said ‘rmail-mime-entity-truncated’
      was defined in mail/rmailmm.el: function not found

This is because rmail-mime-entity-truncated is defined thusly:

  (defsubst rmail-mime-entity-set-truncated (entity truncated)
    (declare (obsolete (setf rmail-mime-entity-truncated) "28.1"))
    (setf (rmail-mime-entity-truncated entity) truncated))

  gnus/gnus-registry.el:436:Warning (check-declare): said
      ‘nnselect-article-group’ was defined in gnus/nnselect.el: function not
      found

This is because nnselect-article-group is defined via define-inline:

  (define-inline nnselect-article-group (article)
    "Return the group for ARTICLE."
    (inline-quote
     (nnselect-artitem-group  (nnselect-artlist-article

It would be nice if check-declare could be taught to DTRT with these.
In case some Lisp construct is infeasible for analyzing correctly,
perhaps some feature could be added to declare-function to cause
check-declare shut up in those particular cases?

In GNU Emacs 29.0.50 (build 1061, i686-pc-mingw32)
 of 2022-05-14 built on HOME-C4E4A596F7
Repository revision: aa98a7823835366a0f06a2103ac183d5f7e59054
Repository branch: master
Windowing system distributor 'Microsoft Corp.', version 5.1.2600
System Description: Microsoft Windows XP Service Pack 3 (v5.1.0.2600)

Configured using:
 'configure -C --prefix=/d/usr --with-wide-int
 --enable-checking=yes,glyphs 'CFLAGS=-O0 -gdwarf-4 -g3''

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NOTIFY
W32NOTIFY PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS WEBP XPM ZLIB

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1255

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr dabbrev emacsbug message mailcap yank-media rmc
puny dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived
epg rfc6068 epg-config gnus-util time-date mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils checkdoc lisp-mnt
thingatpt help-mode vc-git diff-mode easy-mmode vc-dispatcher
cl-loaddefs cl-lib bug-reference seq gv subr-x byte-opt bytecomp
byte-compile cconv warnings compile text-property-search comint
ansi-color ring check-declare iso-transl tooltip eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel dos-w32
ls-lisp disp-table term/w32-win w32-win w32-vars term/common-win
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer nadvice
simple cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese composite
emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help
abbrev obarray oclosure cl-preloaded button loaddefs faces cus-face
macroexp files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads w32notify w32 lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 88977 8875)
 (symbols 48 10820 1)
 (strings 16 27407 2644)
 (string-bytes 1 764566)
 (vectors 16 14945)
 (vector-slots 8 217755 23919)
 (floats 8 33 26)
 (intervals 40 2440 114)
 (buffers 888 43))