[Issue 20881] New: [DIP1000] Templates seem to ignore 'return' (workaround)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri May 29 21:12:23 UTC 2020
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 at puremagic.com
Reporter: stanislav.blinov at 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
}
--
More information about the Digitalmars-d-bugs
mailing list