Subject: 23.3; erroneous byte-compile-file warning

From: Winston <[email-masked]>
Date: Sat, 28 Jul 2012 10:00:31 -0400

GNU Emacs 23.3.1 (amd64-portbld-freebsd9.0, GTK+ Version 2.24.6) of 2011-12-05

It looks like byte-compile-file is issuing a bogus warning for
(set-buffer) inside (save-excursion).

1) The internal description of (save-excursion) says it saves and
   restores point, mark, and the current buffer (just as it's always
   done).  Here's the relevant part of the description (with -->).

    save-excursion is a special form in `C source code'.

    (save-excursion &rest BODY)

    Save point, mark, and current buffer; execute BODY; restore those things.
    Executes BODY just like `progn'.
--> The values of point, mark and the current buffer are restored
    even in case of abnormal exit (throw or error).
    The state of activation of the mark is also restored.

2) This trivial example, run from buffer *scratch*, agrees with that
   description, that the current buffer gets restored:

    (progn
      (save-excursion
        (set-buffer "foo")      ; I'd already created this
        (barf-if-buffer-read-only)
        )
      (current-buffer)
    )
    #<buffer *scratch*>

3) However, when I write that code to foo.el and run byte-compile-file
   on it, I get the following error:

    Compiling file /home/wbe/foo.el at Sat Jul 28 09:07:28 2012
    Entering directory `/home/wbe/'
--> foo.el:1:1:Warning: `save-excursion' defeated by `set-buffer'

It looks to me like the Warning message is untrue.
 -WBE

[The rest is from (report-emacs-bug).  I removed some clearly irrelevant
parts.]

In GNU Emacs 23.3.1 (amd64-portbld-freebsd9.0, GTK+ Version 2.24.6)
 of 2011-12-05 on jail-15
Windowing system distributor `The X.Org Foundation', version 11.0.10707000
configured using `configure  '--localstatedir=/var' '--with-x-toolkit=gtk' '--x-libraries=/usr/local/lib' '--x-includes=/usr/local/include' '--prefix=/usr/local' '--mandir=/usr/local/man' '--infodir=/usr/local/info/' '--build=amd64-portbld-freebsd9.0' 'build_alias=amd64-portbld-freebsd9.0' 'CC=cc' 'CFLAGS=-O2 -pipe -fno-strict-aliasing' 'LDFLAGS= -L/usr/local/lib -rpath=/usr/lib:/usr/local/lib' 'CPPFLAGS=-I/usr/local/include' 'CPP=cpp''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: iso_8859_1
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: C
  value of $XMODIFIERS: nil
  locale-coding-system: iso-latin-1-unix
  default enable-multibyte-characters: t

Major mode: Message

Minor modes in effect:
  mml-mode: t
  gnus-message-citation-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: t

[...]

Load-path shadows:
/home/wbe/lib/info hides /usr/local/share/emacs/23.3/lisp/info

Features:
(shadow emacsbug info gnus-fun warnings compile comint debug apropos pp
etags ring html2text browse-url newcomment novice rect flow-fill
gnus-cite smiley ansi-color mail-extr gnus-bcklg gnus-async byte-opt
bytecomp byte-compile gnus-ml disp-table parse-time timezone nndraft
nnmh auth-source gnus-agent gnus-srvr gnus-score score-mode nnvirtual
gnus-msg gnus-art mm-uu mml2015 pgg pgg-parse pgg-def epg-config mm-view
smime dig nntp gnus-cache gnus-sum nnoo gnus-group gnus-undo nnmail
mail-source format-spec gnus-start gnus-spec gnus-int gnus-range message
sendmail regexp-opt ecomplete rfc822 mml mml-sec password-cache
mm-decode mm-bodies mm-encode mailcap mail-parse rfc2231 rfc2047 rfc2045
qp ietf-drums mailabbrev gmm-utils mailheader canlock sha1 hex-util
hashcash gnus-win gnus gnus-ems nnheader gnus-util netrc time-date
mail-utils mm-util mail-prsvr sort multi-isearch kmacro two-column
iso-transl help-mode view hexl eldoc help-fns cus-edit easymenu
cus-start cus-load wid-edit tooltip ediff-hook vc-hooks lisp-float-type
mwheel x-win x-dnd font-setting tool-bar dnd fontset image fringe
lisp-mode register page menu-bar rfn-eshadow timer select scroll-bar
mldrag mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev loaddefs button minibuffer faces cus-face files text-properties
overlay md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind
system-font-setting font-render-setting gtk x-toolkit x multi-tty emacs)