1.0.46.8: warn about (FORMAT "~A" ...)
authorNikodemus Siivola <nikodemus@random-state.net>
Sun, 20 Feb 2011 10:43:24 +0000 (10:43 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Sun, 20 Feb 2011 10:43:24 +0000 (10:43 +0000)
 Add a compiler-macro that only checks if the destination argument is a
 literal string.

 Fixes lp#327223.

NEWS
src/code/target-format.lisp
tests/print.impure.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index ba3c986..9934248 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ changes relative to sbcl-1.0.46:
   * enhancement: --script muffles style-warnings and compiler notes. (lp#677779)
   * enhancement: redefinition warnings for macros from different files. (lp#434657)
   * enhancement: better MACHINE-VERSION on Darwin x86 and x86-64. (lp#668332)
+  * enhancement: (FORMAT "foo" ...) and similar signal a compile-time warning. (lp#327223)
   * bug fix: SB-DEBUG:BACKTRACE-AS-LIST guards against potentially leaking
     stack-allocated values out of their dynamic-extent. (lp#310175)
   * bug fix: attempts to use SB-SPROF for wallclock profiling on threaded
index 8478a22..bbf357d 100644 (file)
      (%format destination control-string format-arguments)
      nil)))
 
+(define-compiler-macro format (&whole form destination control &rest args)
+  (declare (ignore control args))
+  (when (stringp destination)
+    (warn "Literal string as destination in FORMAT:~%  ~S" form))
+  form)
+
 (defun %format (stream string-or-fun orig-args &optional (args orig-args))
   (if (functionp string-or-fun)
       (apply string-or-fun stream args)
index c773e76..9b4f13d 100644 (file)
                             (write-to-string *print-length* :length nil))))))
     (assert (equal "42" (funcall test)))))
 
+(with-test (:name (:format :compile-literal-dest-string))
+  (assert (eq :warned
+              (handler-case
+                  (compile nil
+                           `(lambda (x) (format "~A" x)))
+                ((and warning (not style-warning)) ()
+                  :warned)))))
+
 ;;; success
index c6e6b0b..ec8bd49 100644 (file)
@@ -20,4 +20,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.46.7"
+"1.0.46.8"