digitalmars.D.bugs - [Issue 16228] New: Insufficient diagnostics for wrong application of
- via Digitalmars-d-bugs (51/51) Jul 02 2016 https://issues.dlang.org/show_bug.cgi?id=16228
https://issues.dlang.org/show_bug.cgi?id=16228 Issue ID: 16228 Summary: Insufficient diagnostics for wrong application of DIP25 Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: major Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: public dicebot.lv Most simple example: ================== void foo ( return ref int ) { } void main ( ) { int x; foo(x); } =================== This code successfully compiles with `dmd -dip25` despite the fact function doesn't return anything by reference and usage of `return ref` on parameter is a certain mistake. Compiler in general doesn't check nonsense applications of return ref making it impossible to reason about feature based on experimentation because "everything is checked good" and "return ref is ignored" produce the same outcome. With more complicated functions it easily misleads developer into believing that `return ref` is capable of more complicated lifetime checking than it is intended too: ===================== int* wrap ( return ref int input ) { return &input; } int* badWrapper() { int x = 5; return wrap(x); // OK } void main() { auto badWrap = badWrapper(); } ===================== Here `return ref` has no effect for same reason as in first example. But lack of compiler errors about such nonsense application may easily lead to believe it is supposed to work. --
Jul 02 2016