www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20881] New: [DIP1000] Templates seem to ignore 'return'

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

          Issue ID: 20881
           Summary: [DIP1000] Templates seem to ignore 'return'
                    (workaround)
           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

// dmd -dip1000

 safe:

struct Correct {
    private int* ptr;
    int* get() return { return ptr; }
}

struct Faulty(T) {
    private T* ptr;
    T* get() return { return ptr; }
}

struct Workaround(T) {
    private T* ptr;
    T* get() return {
        return *&ptr; // workaround is the *&
    }
}

// fails to compile (as it should)
unittest {
    int* outlive;
    Correct c;
    outlive = c.get(); // error
}

// compiles (but shouldn't)
unittest {
    int* outlive;
    Faulty!int f;
    outlive = f.get(); // should be error
}

// fails to compile (as it should)
unittest {
    int* outlive;
    Workaround!int w;
    outlive = w.get(); // error
}

--
May 29