Unintuitive behavior with shared classes & template member functions; is this intended?

Steven Schveighoffer schveiguy at gmail.com
Sat Jan 15 02:52:20 UTC 2022


On 1/14/22 6:10 PM, Jaime wrote:

> Why does this happen? Is it intended behavior? I'm still somewhat new to 
> D, so I'm not prepared to submit this as an issue quite yet; for all I 
> know, there might be a good reason it works this way.

This seems like a bug to me.

> 
> This confusing problem really bit me in the patootie in a personal 
> project earlier. Fortunately, although it was difficult to guess what 
> was going on, once I did, it was an easy fix: namely, a template member 
> function explicitly marked as shared is, of course, compiled as shared, 
> as desired.

I think it always be shared.

Alarmingly, if you have a method, you can't call it on your newly 
constructed non-shared object (because the object isn't shared, but the 
method is).

shared classes on their own are kind of junk. It's supposed to mean that 
everything is shared inside, but you probably can fix the issue via:

```d
class C
{
shared:
    ... // everything
}
```

Please file:  https://issues.dlang.org

-Steve


More information about the Digitalmars-d-learn mailing list