[Issue 13336] New: auto ref return deduced to be ref despite return value coercion
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Aug 19 14:31:11 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13336
Issue ID: 13336
Summary: auto ref return deduced to be ref despite return value
coercion
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: peter.alexander.au at gmail.com
------------------------
int sx;
double sy;
auto ref foo()
{
if (1)
return sx;
return sy;
}
------------------------
foo is determined to return a 'ref double', even though sx is not a double. It
is cast to a double and a ref to the temporary is returned.
Expected behaviour: When common-type coercions are involved, auto ref should
deduce to be non-ref otherwise the code becomes unsafe and surprising.
The spec doesn't say anything about this, it just says "The lexically first
ReturnStatement determines the ref-ness of a function".
--
More information about the Digitalmars-d-bugs
mailing list