Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 2 - Structs with toString() method not formatted properly
Summary: Structs with toString() method not formatted properly
Status: RESOLVED FIXED
Alias: None
Product: GDC
Classification: Unclassified
Component: libgphobos (show other bugs)
Version: development
Hardware: All All
: --- major
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2012-07-15 09:45 CEST by Alex Rønne Petersen
Modified: 2012-09-26 11:26 CEST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Rønne Petersen 2012-07-15 09:45:29 CEST
$ cat test.d
import std.string;

struct S
{
    string toString() { return "foo"; }
}

void main()
{
    format("%s", S());
}
$ gdc test.d
$ ./a.out 
std.format.FormatException@../../../gcc-4.8-20120701/libphobos/std/format.d(4748): cannot portably format a struct on this target
----------------
./a.out() [0x43aa10]
./a.out() [0x4238c3]
./a.out() [0x4239b1]
./a.out() [0x402502]
./a.out() [0x405be1]
./a.out() [0x40608d]
./a.out() [0x406140]
./a.out() [0x40608d]
./a.out() [0x40666c]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7f29b9bb430d]
./a.out() [0x402385]
----------------

This program should print "foo".
Comment 1 Iain Buclaw 2012-07-16 10:14:08 CEST
Documentation on known differences should be updated.

DMD on 64bit has a runtime library implementation that retrieves the next variadic argument based on it's TypeInfo and it's tsize().

eg:  auto va = va_arg(ap, ti);


GDC uses it's GCC's built-in VA_ARG_EXPR, which depends on the type being known at compile time in order to work.

eg: auto va = va_arg!(Foo)(ap);


There is no way around this other than implementing a new runtime function which does a similar job that DMD's implementation does, but have it specific for the way GDC passes variadic arguments to the callee.
Comment 2 Iain Buclaw 2012-08-17 16:28:23 CEST
Implements the remainder va_arg templates missing in GDC runtime.

https://github.com/D-Programming-GDC/GDC/commit/f039c099235636cf64242c21e572fca6c0a5952e


Harmonises doFormat implementation in GDC phobos with upstream so testcase passes.

https://github.com/D-Programming-GDC/GDC/commit/185320fa4ce894fd6a60a1cd398ef7659422924b
Comment 3 Johannes Pfau 2012-09-26 09:01:43 CEST
Can we close this bug report?
Comment 4 Iain Buclaw 2012-09-26 11:26:25 CEST
If your happy. Closed.