www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18548] New: [2.079 Beta] std.format ignores templated


          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 puremagic.com
          Reporter: jack jackstouffer.com


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

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.

Mar 02 2018