Bug 16228 – Insufficient diagnostics for wrong application of DIP25

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-07-02T09:49:00Z
Last change time
2016-10-01T11:48:17Z
Keywords
pull, safe
Assigned to
nobody
Creator
public

Comments

Comment #0 by public — 2016-07-02T09:49:16Z
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.
Comment #1 by bugzilla — 2016-07-03T00:05:35Z
Comment #2 by bugzilla — 2016-07-03T02:00:50Z
BTW, you'll see errors diagnosed if @safe is added. Leaving off @safe disables safety checks.
Comment #3 by public — 2016-07-03T09:08:55Z
> BTW, you'll see errors diagnosed if @safe is added. Leaving off @safe disables safety checks. This doesn't sound right - these errors are akin to syntax errors in spirit, such usage of `return ref` can't be possibly correct, @safe or not.
Comment #4 by public — 2016-07-03T09:20:42Z
Also: is `return ref` supposed to work with @trusted exactly the same as with @safe?
Comment #5 by github-bugzilla — 2016-07-05T02:38:26Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/facb2aefd3d4509c0f1976287824af20d29addd6 fix Issue 16228 - Insufficient diagnostics for wrong application of DIP25 https://github.com/dlang/dmd/commit/740b05022995a644c23d373b956340fe699c3e11 Merge pull request #5901 from WalterBright/fix16228 fix Issue 16228 - Insufficient diagnostics for wrong application of D…
Comment #6 by github-bugzilla — 2016-10-01T11:48:17Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/facb2aefd3d4509c0f1976287824af20d29addd6 fix Issue 16228 - Insufficient diagnostics for wrong application of DIP25 https://github.com/dlang/dmd/commit/740b05022995a644c23d373b956340fe699c3e11 Merge pull request #5901 from WalterBright/fix16228