Allow Explicit Pointer for Auto Declaration

Mike Parker via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 29 20:07:41 PDT 2016


On Friday, 30 September 2016 at 01:48:02 UTC, Jacob wrote:

> auto* pValue = expr;  // still invalid code unless expr 
> evaluate to a pointer type
> auto* pValue = &expr; // this is valid if expr is a ref
>
> It still requires the &, what it prevents is this situation:
>
> auto pValue = expr; // wanted pointer, expr evaluates to 
> non-ptr value through change of code or simply forgetting "&"
>
> So no code should be broken, you can do everything the same way 
> without a change in behavior and auto with a "*" is currently 
> invalid.
>
> Basically how it works in C++: http://ideone.com/TUz9dO

You could forget the * just as easily as the &.


More information about the Digitalmars-d mailing list