Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions std/format.d
Original file line number Diff line number Diff line change
Expand Up @@ -1885,9 +1885,24 @@ if ((is(T == struct) || is(T == union)) && !isInputRange!T)
put(w, left);
foreach (i, e; val.tupleof)
{
static if (i > 0)
put(w, separator);
formatElement(w, e, f);
static if (0 < i && val.tupleof[i-1].offsetof == val.tupleof[i].offsetof)
{
static if (i == val.tupleof.length - 1 || val.tupleof[i].offsetof != val.tupleof[i+1].offsetof)
put(w, separator~val.tupleof[i].stringof[4..$]~"}");
else
put(w, separator~val.tupleof[i].stringof[4..$]);
}
else
{
static if (i+1 < val.tupleof.length && val.tupleof[i].offsetof == val.tupleof[i+1].offsetof)
put(w, (i > 0 ? separator : "")~"#{overlap "~val.tupleof[i].stringof[4..$]);
else
{
static if (i > 0)
put(w, separator);
formatElement(w, e, f);
}
}
}
put(w, right);
}
Expand Down Expand Up @@ -1954,6 +1969,29 @@ unittest
assert(a.data == "hello");
}

unittest
{
// 7230
static struct Bug7230
{
string s = "hello";
union {
string a;
int b;
double c;
}
long x = 10;
}

Bug7230 bug;
bug.b = 123;

FormatSpec!char f;
auto w = appender!(char[])();
formatValue(w, bug, f);
assert(w.data == `Bug7230("hello", #{overlap a, b, c}, 10)`);
}

/**
Static-size arrays are formatted just like arrays.
*/
Expand Down