[Issue 4232] New: Local struct member variable can be returned by ref
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon May 24 23:21:54 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4232
Summary: Local struct member variable can be returned by ref
Product: D
Version: 2.041
Platform: x86
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: rsinfu at gmail.com
--- Comment #0 from Shin Fujishiro <rsinfu at gmail.com> 2010-05-24 23:21:52 PDT ---
Using struct members bypasses the compiler check for escaping reference to
local variables.
This code should not compile:
--------------------
struct S { int a; }
ref int test()
{
S s;
s.a = 42;
return s.a;
}
void main()
{
auto p = &test(); // reference to the local variable
assert(test() == 42); // assertion fails with -O
}
--------------------
Moreover, test() in the above example returnes a corrupted (or uninitialized)
value when optimization is on. This causes unittests for
std.functional.toDelegate() to segfault.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list