[Issue 12625] implicit slicing of RValue static array should be illegal
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Apr 14 06:30:11 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=12625
Steven Schveighoffer <schveiguy at yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |schveiguy at yahoo.com
Severity|normal |enhancement
--- Comment #7 from Steven Schveighoffer <schveiguy at yahoo.com> ---
This came up in the newsgroup:
(https://forum.dlang.org/post/xvoisyksvutaaktqaswl@forum.dlang.org)
I think we can say safely that slicing an rvalue return cannot lead to anything
good.
As for the example of why it should be allowed, I'm not convinced. That example
requires blind faith that the receiver of the slice never does anything bad
with it, and assumes the compiler doesn't cleverly reclaim the memory for the
rvalue seeing as it wasn't used anywhere. We should reject it for the same
reason we reject fun(&generateSomeInt()). Sure, fun may not do anything bad,
but it has a lot of leeway to do so.
Not sure how to up the importance of this.
Note, let's not confuse this issue with slicing of a static array that has
dedicated stack space (i.e. not a temporary). That may also be rendered an
error somehow, but this is vastly more erroneous.
--
More information about the Digitalmars-d-bugs
mailing list