[Issue 5115] std.typecons.scoped problems
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 18 13:03:04 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5115
Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrej.mitrovich at gmail.com
--- Comment #11 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-12-18 13:02:40 PST ---
(In reply to comment #10)
> Now bug 3516 was fixed. Then comment#1 code prints two "Foo.dtor"
>
> But allowing conversion from temporary type (e.g. Scoped!Foo) to Foo is unsafe,
> because the temporary has value type and its lifetime is limited in its scope,
> but Foo is class reference of the temporary and we can bring it out the scope.
There is another problem. You may want to pass the instance to another
function, which is ok since the type will still be alive during that call:
class C { }
void func(C c) { }
void main()
{
auto c = scoped!C();
func(c); // ok, c is still alive here
}
Disabling implicit conversion (maybe by using your ProxyOf mixin) might be ok,
but then we can no longer pass the instance around because `Scoped` is a
voldemort type hidden inside the `scoped` function. E.g.:
class C { }
void func(C c) { }
void funcScoped(??? c) { } // param needs to be a proper type
void main()
{
auto c = scoped!C(); // voldemort type
func(c); // error, no implicit conversion
funcScoped(c); // would be ok if we knew what type c was
}
So if we disable implicit conversion we should probably introduce a Scoped type
instead of a voldemort, so we can write:
void funcScoped(ref Scoped!C c) { }
--
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