www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19408] New: nothrow inference fails (template + postblit)

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

          Issue ID: 19408
           Summary: nothrow inference fails (template + postblit)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: stanislav.blinov gmail.com

struct Infidel(T) {
    T value;
    T get() { return value; } // returns a copy
}

void main() {
    static struct S {
        int x;
        this(this) {
            if (x > 0) throw new Exception("fail");
            else x = 1;
        }
    }
    // passes, cannot nothrow-copy
    static assert(!is(typeof(() nothrow { S* x; union U { S x; } U u = U(*x);
})));
    // passes, copy may throw
    static assert(is(typeof(() { S* x; union U { S x; } U u = U(*x); })));

    S s;
    auto sneak = Infidel!S(s); // won't throw here, s.x was 0

    // fails but shouldn't:
    static assert(!is(typeof(() nothrow { auto x = sneak.get(); })));

    import std.exception;
    // compiles (but shouldn't), and passes:
    assertThrown(() nothrow {
        auto x = sneak.get();
    }());
}

--
Nov 17 2018