Bug 18548 – [2.079] std.format ignores templated toString if another toString is not a template

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-02T19:55:53Z
Last change time
2018-03-13T02:31:12Z
Assigned to
No Owner
Creator
Jack Stouffer

Comments

Comment #0 by jack — 2018-03-02T19:55:53Z
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.
Comment #1 by github-bugzilla — 2018-03-13T02:31:11Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/3d5cb4a0f7d0889a1f6b3830d3efada7177260aa Fix Issue 18548 - std.format ignores templated toString if another toString is not a template https://github.com/dlang/phobos/commit/2612d38b55d8aa313b3f8d47352f6d45fc341a85 Merge pull request #6247 from JackStouffer/issue18548 Fix Issue 18548 - std.format ignores templated toString if another to…