Remove declaration 'auto' for RAII?

Chris Miller chris at dprogramming.com
Mon Mar 13 05:20:27 PST 2006


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. 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.



More information about the Digitalmars-d mailing list