Code behaves incorrectly if it is compiled in std.functional

Mafi via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 5 13:36:19 PDT 2015


On Friday, 5 June 2015 at 10:56:36 UTC, ketmar wrote:

>
> p.s. if "auto" is a storage class, the following code should be 
> accepted
> (while it isn't):
>
>   int foo () { return 42; }
>
>   void main () {
>     auto auto i = foo();
>   }
>
> as it's logically "an auto-typed var with "auto" storage class".

Here lies your mistake. There is no such thing as "auto"-typed 
(leaving aside function signatures, which might be special-cased 
and are different beast altogether). Auto is not a type. auto* or 
auto[] aren't valied either. Auto is just a storage class, no 
more, no less. You use it if the grammar needs a storage class 
but you don't want to give special attributes to the variable 
(like const or static). To make a declaration with inferred type 
you need at least one storage class. To make it work with 
"normal" variables you use "auto".


More information about the Digitalmars-d mailing list