Notes from C++ static analysis

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Jun 26 13:05:04 PDT 2013


On Wed, Jun 26, 2013 at 09:07:30PM +0200, Adam D. Ruppe wrote:
> On Wednesday, 26 June 2013 at 18:54:17 UTC, H. S. Teoh wrote:
> >>import std.stdio;
> >>void main() {
> >>    size_t x = 10;
> >>    writefln("%d", x, x);
> >>}
> >>
> >>In a modern statically typed language I'd like such code to give
> >>a compile-time error.
> >
> >This looks like a bug to me. Please file one. :)
> 
> Not necessarily, since you might want a format string to be a
> runtime variable, like when doing translations. I could live with
> there being another function that does runtime though.
[...]

Wait, I thought we were talking about *compile-time* warnings for
extraneous arguments to writefln. If the format string is not known at
compile-time, then there's nothing to be done, and as you said, it's
arguably better to allow more arguments than format specifiers if you're
doing i18n.

But if the format string is known at compile-time, and there are
extraneous arguments, then it should be a warning / error.


T

-- 
People tell me that I'm skeptical, but I don't believe it.


More information about the Digitalmars-d mailing list