DMD 0.148 - regular expressions
Brad Roberts
braddr at puremagic.com
Mon Mar 6 11:49:53 PST 2006
On Mon, 6 Mar 2006, Walter Bright wrote:
> "Ivan Senji" <ivan.senji_REMOVE_ at _THIS__gmail.com> wrote in message
> news:dubrop$118j$1 at digitaldaemon.com...
> > Will this work:
> >
> > if( auto a = something() && auto b = something())
> >
> > a more general solution of declaring/initializing variables by parts of
> > expressions?
>
> No, it won't work. Embedding declarations inside expressions leads to all
> sorts of problems, not the least of which is what happens in this scenario:
>
> if (auto a = foo() || auto b = bar())
> {
> a + b; // is b declared or not?
> }
Easy enough to define the behavior. I'm not sure what an
appropriate term is for variables declared like this, so insert
something appropriate below. Something like this would work reasonably
well, probably:
For all variables declared in an if expression, they will be default
initialized if their initializing expression is not executed due to short
circuit evaluation.
So..
if (auto /* int */ res1 = someIntegerExpression() ||
auto /* int */ res2 = someOtherIntegerExpression())
{
return res1 + res2;
}
The results of that become well defined. What would be potentially
problematic is if return types are ever added to function overloading /
resolution. But I won't get into my opinions on that or on implicit
typing as it's ornthogonal to this topic.
Later,
Brad
More information about the Digitalmars-d
mailing list