From e1ed4073f01962ff46a227ffb8a852d42070dee6 Mon Sep 17 00:00:00 2001 From: Nikodemus Siivola Date: Sun, 20 Feb 2011 10:43:24 +0000 Subject: [PATCH] 1.0.46.8: warn about (FORMAT "~A" ...) Add a compiler-macro that only checks if the destination argument is a literal string. Fixes lp#327223. --- NEWS | 1 + src/code/target-format.lisp | 6 ++++++ tests/print.impure.lisp | 8 ++++++++ version.lisp-expr | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index ba3c986..9934248 100644 --- 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 diff --git a/src/code/target-format.lisp b/src/code/target-format.lisp index 8478a22..bbf357d 100644 --- a/src/code/target-format.lisp +++ b/src/code/target-format.lisp @@ -51,6 +51,12 @@ (%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) diff --git a/tests/print.impure.lisp b/tests/print.impure.lisp index c773e76..9b4f13d 100644 --- a/tests/print.impure.lisp +++ b/tests/print.impure.lisp @@ -501,4 +501,12 @@ (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 diff --git a/version.lisp-expr b/version.lisp-expr index c6e6b0b..ec8bd49 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -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" -- 1.7.10.4