Bug or logic error in if with auto?

Rob T rob at ucora.com
Mon Dec 3 12:17:41 PST 2012


On Monday, 3 December 2012 at 14:22:28 UTC, Nick Treleaven wrote:

> Most programmers would probably just pollute the existing scope:
>
> auto x = "thing" in arr;
> if (x && *x == 45)
> {
>     ...
> }
>

You can always wrap it inside its own scope

main()
{
   // temp scope
   {
     auto x = "thing" in arr;
     if (x && *x == 45)
     {
        ...
     }
   }

   writeln(x); // <- error x is undefined

}




More information about the Digitalmars-d mailing list