Bug 22990 – [dip1000] extended return semantics doesn't work on auto return

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-05T15:21:03Z
Last change time
2024-12-13T19:22:07Z
Assigned to
No Owner
Creator
Dennis
Moved to GitHub: dmd#20084 →

Comments

Comment #0 by dkorpel — 2022-04-05T15:21:03Z
``` auto assign(ref scope int* x, return ref int y) @safe { x = &y; } auto assign(ref scope int* x, return scope int* y) @safe { x = y; } ``` Error: address of variable `y` assigned to `x` with longer lifetime Error: scope variable `y` assigned to `x` with longer lifetime Change the return type to `void` and it passes. The function `isFirstRef()` returns false when the return type is not determined yet.
Comment #1 by bugzilla — 2022-09-01T02:16:40Z
Your analysis is correct, it's the `if (!tf.nextOf()) return false;`. Perhaps the function can set a flag if it doesn't see any `return` statements.
Comment #2 by bugzilla — 2022-09-01T03:57:54Z
(In reply to Walter Bright from comment #1) > Perhaps the function can set a flag if it doesn't see any `return` > statements. Eh, that means scanning the statement AST before semantic analysis, i.e. slow. I don't think this is a particular problem anyway, as why would one return `auto` if there are no `return` statements?
Comment #3 by dkorpel — 2022-09-12T12:24:28Z
(In reply to Walter Bright from comment #2) > (In reply to Walter Bright from comment #1) > > Perhaps the function can set a flag if it doesn't see any `return` > > statements. > > I don't think this is a particular problem anyway, as why would one return > `auto` if there are no `return` statements? To enable attribute inference on the function, or because it's a generic function which returns based on template parameters. I don't have a concrete use case so I don't think there's much priority to support this, but if it's not going to be supported, then at least the limitation should be in the specification.
Comment #4 by robert.schadek — 2024-12-13T19:22:07Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20084 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB