www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15061] New: std.experimental.logger uses safe on function

https://issues.dlang.org/show_bug.cgi?id=15061

          Issue ID: 15061
           Summary: std.experimental.logger uses  safe on function
                    templates
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: renezwanenburg gmail.com

This means I can't log structs with a custom toString(). For example,

import std.experimental.logger;

struct S
{
    string toString()
    {
        return "";
    }
}

void main()
{
    S s;
    tracef("%s", s);
}


Results in

Error: safe function
'std.experimental.logger.core.Logger.memLogFunctions!cast(LogLevel)cast(ubyte)32u.logImplf!(15,
"test.d", "test.main", "void test.main()", "test", S).logImplf' cannot call
system function 'std.format.formattedWrite!(MsgRange, char, S).formattedWrite'

A workaround is to change
tracef("%s", s);
into
tracef("%s", s.toString());

--
Sep 15 2015