D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4754 - format and Format!() do not work with posix positional parameters
Summary: format and Format!() do not work with posix positional parameters
Status: RESOLVED DUPLICATE of issue 4532
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-29 03:29 UTC by Jonathan M Davis
Modified: 2012-04-10 03:38 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2010-08-29 03:29:49 UTC
The following program fails to compile:

import std.metastrings;
import std.stdio;

void main()
{
    mixin(Format!("writeln(\"%1$s\");", "hello world"));
}


Instead, you get this error:

/path/to/src/phobos/std/metastrings.d(69): Error: static assert  "unrecognized format %1"
/path/to/src/phobos/std/metastrings.d(51):        11 recursive instantiations from here: FormatString!("writeln(\"%1$s\");","hello world")
d.d(6):        instantiated from here: Format!("writeln(\"%1$s\");","hello world")

So, it would appear that Format!() fails to work with posix positional parameters. If you replace %1$s with %s, it works just fine. Also, if you attempt to use format() with %1$s, it throws a FormatError at runtime. I would expect that format and Format!() would accept exactly the same types of input as writefln(). However, that does not appear to currently be the case. Certainly, having them differ in capabilities is going to cause a fair bit of confusion. So, they need to be fixed to work with the same input as writefln(). In particular, they need to support posix positional parameters.
Comment 1 Stewart Gordon 2012-04-10 03:38:13 UTC

*** This issue has been marked as a duplicate of issue 4532 ***