Remove declaration 'auto' for RAII?

Stewart Gordon smjg_1998 at yahoo.com
Wed Mar 15 08:06:44 PST 2006


Chris Miller wrote:
> There is a problem with auto when declaring variables!
> 
> Not only does it have 2 meanings, but when using it for implicit type 
> inference, it no longer has the RAII quality. So if you say "auto foo = 
> 1" is much like "static bar = 1", you are mistaken. The 2nd one doesn't 
> cause it to be non-static, so why does the 1st make it non-RAII?
> 
> If auto for implicit type inference stays, I propose removing it for 
> RAII in declarations.

The RAII meaning of auto came first.  D programmers from pre-0.137 days 
are going to be confused when they discover that auto has nothing in 
common with its old self.

> If you want RAII you can simply use scope(exit) 
> delete baz; after the declaration. Also, the "auto class {}" form can 
> still stay since it is in unrelated code and there is no easy 
> replacement for it.

OK, so it will still have this in common.  But the way the auto keyword 
is overloaded will look no less a mess.

If we're going to change the auto keyword, we should change at least one 
of its meanings to be denoted by a whole new keyword.

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:- C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- 
PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.



More information about the Digitalmars-d mailing list