[Issue 21228] Templated toString silently ignored when it cant be instantiated

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Sep 5 22:18:18 UTC 2020


Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
                 CC|                            |simen.kjaras at gmail.com
            Summary|OutputRange-based toString  |Templated toString silently
                   |is silently ignored if      |ignored when it cant be
                   |isOutputRange is not        |instantiated
                   |imported                    |

--- Comment #2 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
All of the below cases are instances of this same issue:

struct S1 {
    string toString()() {

struct S2 {
    void toString(R)(ref R r) if (isOutputRange!(R, char)) {}

struct S3 {
    import std.range : isOutputRange;
    void toString(R)(ref R r) if (isOutputRange!(R, char)) {

unittest {
    import std.conv : to;
    assert(S1().to!string == "S1()");
    assert(S2().to!string == "S2()");
    assert(S3().to!string == "S3()");

formatValueImpl in std.format already tests for @disabled toString - it should
also test for instantiability.


More information about the Digitalmars-d-bugs mailing list