www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - refCounted not safe?

reply Steven Schveighoffer <schveiguy gmail.com> writes:
struct S {}

void main()  safe
{
    import std.typecons;
    auto s = S().refCounted;
}

Error:  safe function D main cannot call  system function 
std.typecons.refCounted!(S).refCounted
Error:  safe function D main cannot call  system destructor 
std.typecons.RefCounted!(S, 
cast(RefCountedAutoInitialize)0).RefCounted.~this

How do I do refCounted in  safe code?
May 01 2020
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Fri, May 01, 2020 at 05:31:57PM -0400, Steven Schveighoffer via
Digitalmars-d wrote:
 struct S {}
 
 void main()  safe
 {
    import std.typecons;
    auto s = S().refCounted;
 }
 
 Error:  safe function D main cannot call  system function
 std.typecons.refCounted!(S).refCounted
 Error:  safe function D main cannot call  system destructor
 std.typecons.RefCounted!(S,
 cast(RefCountedAutoInitialize)0).RefCounted.~this
 
 How do I do refCounted in  safe code?
Use trusted. :-/ T -- Time flies like an arrow. Fruit flies like a banana.
May 01 2020
prev sibling parent 12345swordy <alexanderheistermann gmail.com> writes:
On Friday, 1 May 2020 at 21:31:57 UTC, Steven Schveighoffer wrote:
 struct S {}

 void main()  safe
 {
    import std.typecons;
    auto s = S().refCounted;
 }

 Error:  safe function D main cannot call  system function 
 std.typecons.refCounted!(S).refCounted
 Error:  safe function D main cannot call  system destructor 
 std.typecons.RefCounted!(S, 
 cast(RefCountedAutoInitialize)0).RefCounted.~this

 How do I do refCounted in  safe code?
You can't. You can't make it safe, unless you fix the bug regarding destructors not being attribute friendly. -Alex
May 01 2020