Not initialized out argument error
Tobias Pankrath via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 17 02:14:20 PDT 2014
>
> What if x is an "optional" out parameter: EG: something you
> only set if other conditions are met? Do you want to make sure
> that x is at least assigned to once, or rather make it an error
> to have a control path that *doesn't* assign anything to it.
>
> Either way:
> 1. Making it an error to have a control path that doesn't
> assign to x would be counter productive, as the result would
> probably end up being code that looks like:
> foo(out int x) {
> x = 0;
> ...
> }
> which would defeat the entire point of out.
> 2. Checking the variable is at least used would be kind of the
> same as checking for unused arguments. I think that'd be fine,
> provided you could over-ride the warning by not naming your
> variable:
> foo(out int x){} //Error, x is never assigned to (or used)
> foo(out int){} //OK!
Today a function with return value but without return statement
is already an error. Why not return ReturnType.init instead? It's
absolutely the same.
More information about the Digitalmars-d
mailing list