auto storage class - infer or RAII?

Tomas Lindquist Olsen tomas at famolsen.dk
Mon Nov 13 13:20:21 PST 2006


Sean Kelly wrote:
> Tomas Lindquist Olsen wrote:
>> Sean Kelly wrote:
>>> Tomas Lindquist Olsen wrote:
>>>> Another argument for using 'auto' for ATI can be making it 
>>>> consistent with how it currently works for classes in DMD:
>>>>
>>>> class A
>>>> {
>>>>     static
>>>>     {
>>>>         auto x = 2;
>>>>         auto y = 42;
>>>>     }
>>>>     auto z = 27;
>>>> }
>>>>
>>>> This works. x and y are static!
>>>
>>> I think this works everywhere, as you're free to chain storage 
>>> classes to your heart's delight:
>>>
>>>     // what is this??
>>>     auto const static const static auto x = 5;
>>>
>>>
>>> Sean
>>
>> That does not work:
>> scopetest.d(29): redundant storage class 'const'
>> scopetest.d(29): redundant storage class 'static'
>> scopetest.d(29): redundant storage class 'auto'
> 
> Oh, so you can just do:
> 
>     auto const static x = 5;
> 
> Could be worse, I suppose.
> 
> Sean

It is definitely a bit weird. I would like to see all combinations of 
these fail. they dont make any sense together. all provide ATI if 
present. the only problem I can see is if you want to put a constant 
inside a static block. but maybe that is handled differently?

IMHO this would make sense:

Invalid:
---------
static const x = 5;
const static x = 5;
const
{
	static x = 5;
}
any combination of auto and const/static

Valid:
---------
const x = 5;
static x = 5;
static
{
	const x = 5;
	auto x = 5;
}
const
{
	auto x = 5;
}

Did I forget any?



More information about the Digitalmars-d mailing list