D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8065 - No way to write function/delegate literals returning ref T
Summary: No way to write function/delegate literals returning ref T
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on: 8064
Blocks:
  Show dependency treegraph
 
Reported: 2012-05-08 03:42 UTC by Gašper Ažman
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Gašper Ažman 2012-05-08 03:42:20 UTC
Currently, I (with the help of #D on irc.freenode.net) couldn't find any way to define a function or delegate literal returning a reference.

our best guess at the syntax was

delegate ref T (params) { body }

or, to be more general,

delegate ATTRIBUTE T (params) { body }

example:
void main() {
    auto bar = new int[5];
    auto foo = delegate ref int(size_t i) { return bar[i]; };
}

This example fails with the error "basic type expected, not ref".

Note: even if this did work, assigning functions returning ref does not work properly, so this bug depends on #8064.
Comment 1 basile-z 2017-03-09 21:48:18 UTC
Changed to enhancement. This is not even something that exist in the grammar, which would have to be changed to something like


delegate Typeopt refopt ParameterMemberAttributes opt FunctionLiteralBody
Comment 2 Dlang Bot 2019-04-05 20:06:18 UTC
@BorisCarvajal updated dlang/dmd pull request #9558 "Fixes issues 16271, 18825, 8065, 5050 - Allow function literals return by reference" fixing this issue:

- Fixes issues 16271, 18825, 8065, 5050 - Allow function literals return by reference

https://github.com/dlang/dmd/pull/9558
Comment 3 Dlang Bot 2019-04-07 16:18:46 UTC
dlang/dmd pull request #9558 "Fixes issues 16271, 18825, 8065, 5050 - Allow function literals return by reference" was merged into master:

- 60251b8f0e191a8f0f5142ddd2d3807d0e06c58a by Boris Carvajal:
  Fixes issues 16271, 18825, 8065, 5050 - Allow function literals return by reference

https://github.com/dlang/dmd/pull/9558