[Issue 18548] New: [2.079 Beta] std.format ignores templated toString if another toString is not a template
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 2 19:55:53 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18548
Issue ID: 18548
Summary: [2.079 Beta] std.format ignores templated toString if
another toString is not a template
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: jack at jackstouffer.com
Consider
------
import std.format;
import std.range;
struct A(T)
{
string toString() const { return ""; }
void toString(W)(ref W w) const { put(w, ""); }
}
struct B(T)
{
string toString()() const { return ""; }
void toString(W)(ref W w) const { put(w, ""); }
}
void main()
{
// hasToString is a private template of std.format
pragma(msg, hasToString!(A!(int), char)); // 1
pragma(msg, hasToString!(B!(int), char)); // 5
}
------
The issue comes from this line
https://github.com/dlang/phobos/blob/8f0094593c18466095da3156d6d574c93c26466c/std/format.d#L3627
Because the first toString overload in A is not a template but a function, the
attempted instantiation of the toString template inside hasToString always
fails despite the fact that there is an existing toString template.
--
More information about the Digitalmars-d-bugs
mailing list