www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18436] New: broken opCast fails silently when used with

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

          Issue ID: 18436
           Summary: broken opCast fails silently when used with
                    std.conv.to
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: elpenguino+D gmail.com

Invalid code like the following will (correctly) fail to compile, but the error
preventing it from compiling will not be shown to the user.

struct X {
    T opCast(T)() {
        nonexistent();
        return T.init;
    } 
}

assert(X().to!bool == bool.init);

The compiler ought to complain about nonexistent being undefined instead of
simply failing to match toImpl's template declaration.

--
Feb 13 2018