From ab93c469f0332b3314cd1a092a64aecf7e50b7e5 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Fri, 23 Feb 2018 01:53:53 +0100 Subject: [PATCH] Add another test for #7879 --- std/format.d | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/std/format.d b/std/format.d index 17f35f9831f..521d2e955da 100644 --- a/std/format.d +++ b/std/format.d @@ -3868,6 +3868,26 @@ version(unittest) assert(s == "shared(std.format.C)"); } +// https://issues.dlang.org/show_bug.cgi?id=7879 +@safe unittest +{ + class F + { + override string toString() const @safe + { + return "Foo"; + } + } + + const(F) c; + auto s = format("%s", c); + assert(s == "null"); + + const(F) c2 = new F(); + s = format("%s", c2); + assert(s == "Foo", s); +} + // ditto private void formatValueImpl(Writer, T, Char)(auto ref Writer w, T val, const ref FormatSpec!Char f) if (is(T == interface) && (hasToString!(T, Char) || !is(BuiltinTypeOf!T)) && !is(T == enum))