Auto syntax revisited

Georg Wrede georg.wrede at nospam.org
Tue Feb 21 01:27:15 PST 2006


Georg Wrede wrote:
> Mike Capp wrote:
> 
>> In article <dtdb2e$2lsp$1 at digitaldaemon.com>, Sean Kelly says...
>>
>>> If we're moving towards stack-based auto classes then I'd prefer
>>> the distinction be associated with the object and not the
>>> reference.  ie.
>>>
>>> auto foo = local Bar();
>>>
>>> I think the distinction is important because foo can be reassigned
>>> to a non-local object.
>>
>>
>> Not currently, it can't. From
>> http://www.digitalmars.com/d/attribute.html#auto : "Assignment to an
>> auto, other than initialization, is not allowed."
> 
> 
> If 'local' were implemented, then it could, since then the meaning of 
> 'auto' would only mean auto-typing and not RAII.

On second thought,

local Bla bla = new Bla();     // RR, heap storage
auto bla = new Bla();          // autotyped, heap storage
Bla bla = new Bla();           // heap storage
local Bla bla = local Bla();   // RR, stack storage
auto bla = local Bla();        // autotyped, stack storage, no RR
Bla bla = local Bla();         // stack storage, no RR

This brings up a few problems. First, the word 'local' is just about as 
smart as 'auto', i.e. it is misleading and ambiguous for what we're 
using it for.

Second, do we really need this fine of a control over both storage and 
disposal?

For the compiler writer, at first sight, keeping track of RR (RAII) here 
might look like a lot of work. But it actually is ok: "the variable 
knows" whether to invoke RR, so RR will be invoked irrespective of who 
happens to be referenced by it.

This may actually open up new ways of using RR?

One potential, hard problem is, this decouples RR-ness from the object 
instance, making it a property of the reference (the variable). This is 
obviously not in the spirit of why we have RR in the first place.

----

Unless we can sort out what we want here, I think the current state of 
RR is adequate -- _except_ that I want another word substituted for 
'auto'! We can't have it mean "autotype and/or RAII", at the same time. 
That is just too much of a disgrace.



More information about the Digitalmars-d mailing list