1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Augment -Wformat' analysis with support for ~:h'.

* module/language/tree-il/analyze.scm (format-string-argument-count):
  Add support for ~h.

* test-suite/tests/tree-il.test ("warnings")["format"]("~h", "~:h with
  locale object", "~:h without locale object"): New tests.
This commit is contained in:
Ludovic Courtès 2012-02-03 16:52:15 +01:00
parent afd08fdf87
commit b4af80a423
2 changed files with 33 additions and 1 deletions

View file

@ -1,6 +1,6 @@
;;; TREE-IL -> GLIL compiler
;; Copyright (C) 2001, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
;; Copyright (C) 2001, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@ -1328,6 +1328,12 @@ accurate information is missing from a given `tree-il' element."
;; We don't have enough info to determine the exact number
;; of args, but we could determine a lower bound (TODO).
(values 'any 'any))
((#\h #\H)
(let ((argc (if (memq #\: params) 2 1)))
(loop (cdr chars) 'literal '()
conditions end-group
(+ argc min-count)
(+ argc max-count))))
(else (loop (cdr chars) 'literal '()
conditions end-group
(+ 1 min-count) (+ 1 max-count)))))

View file

@ -2243,6 +2243,32 @@
(number? (string-contains (car w)
"expected 1, got 2")))))
(pass-if "~h"
(null? (call-with-warnings
(lambda ()
(compile '((@ (ice-9 format) format) #t
"foo ~h ~a~%" 123.4 'bar)
#:opts %opts-w-format
#:to 'assembly)))))
(pass-if "~:h with locale object"
(null? (call-with-warnings
(lambda ()
(compile '((@ (ice-9 format) format) #t
"foo ~:h~%" 123.4 %global-locale)
#:opts %opts-w-format
#:to 'assembly)))))
(pass-if "~:h without locale object"
(let ((w (call-with-warnings
(lambda ()
(compile '((@ (ice-9 format) format) #t "foo ~,2:h" 123.4)
#:opts %opts-w-format
#:to 'assembly)))))
(and (= (length w) 1)
(number? (string-contains (car w)
"expected 2, got 1")))))
(with-test-prefix "conditionals"
(pass-if "literals"
(null? (call-with-warnings