[Issue 19183] DIP1000 defeated if auto used instead of scope in variable declaration with template this member function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 22 09:51:19 UTC 2018


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

anonymous4 <dfj1esp02 at sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #10 from anonymous4 <dfj1esp02 at sneakemail.com> ---
You can use a wrapper to mark data as unsafe:

@safe:

const(int)* gInts;

void main() {
    auto s = MyStruct(10);
    gInts = s.ints; //error, can't call @system unwrap
}

struct MyStruct
{
    import core.stdc.stdlib;
    Unsafe!(int*) ints;
    this(int size) @trusted { ints = cast(int*) malloc(size); }
    ~this() { () @trusted { free(ints); }(); }
    scope ptr(this This)() { return ints; }
}

struct Unsafe(T)
{
    private T data;
    @system:
    @disable this(this);
    this(T val){ data=val; }
    void opAssign(T val){ data=val; }
    T unwrap(){ return data; }
    alias unwrap this;
}

--


More information about the Digitalmars-d-bugs mailing list