DIP77 - Fix unsafe RC pass by 'ref'

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 9 13:21:12 PDT 2015


On Thursday, 9 April 2015 at 18:44:10 UTC, Walter Bright wrote:
> On 4/9/2015 5:05 AM, Michel Fortin wrote:
>> Why should it not have an opAssign marked @system?
>
> "Andrei's idea was to not do the copy for @system opAssign's, 
> thus providing C++ equivalence for those folks that need it and 
> don't care about guaranteed memory safety."
>

Why not bind this behavior to extern(C++) ?

> The only real purpose to a postblit is to support ref counting. 
> Why would a by-value container use a postblit and not ref count?
>

In C++, the only real purpose of template were generic 
containers, and that didn't ended up well.

It is dangerous, at language level, to reason from usage instead 
of first principle (not that usage do not matter, usage should 
serve as a guideline for the principles) or thing like C++ 
templates happens.

> My first impression is that's too complicated for the user to 
> get right.

Yeah, I don't think opPin is a the right way to go. It is always 
easy and tempting to add new stuff to make X or Y work, but at 
the end, it only create language complexity explosion.

There are some inefficiencies involved here, but I trust the 
compiler to be able to optimize it away for the most part, and we 
have a backdoor for thoses who want to bypass safety.

More generally, this is why I oppose the return attribute + 
adding op on reference type in favor of a principle scope 
proposal. The first one is 2 language features for a less general 
end result.


More information about the Digitalmars-d mailing list