On Thursday, 16 February 2017 at 21:05:51 UTC, Stefan Koch wrote:
...
|| works also fine now ... on it's own.
As soon as || and && are mixed wired things happen.
I am happy that the combinations I tried do at least expose the
issue.
This is one of the things that you can totally overlook if the
test-case does not trigger it.
int[2] aaa2(bool b1, bool b2, bool b3, bool b4)
{
int x = 0;
if (b1 && ++x && b2 && x++ && b3 && (b4 || x++))
{
return [x, 1];
}
else
{
return [x, 0];
}
}
static assert(aaa2(1, 0, 1, 0) == [1, 0]);
//static assert(aaa2(1, 1, 1, 0) == [3, 1]); // argh
static assert(aaa2(1, 1, 1, 1) == [2, 1]);
static assert(aaa2(0, 0, 1, 0) == [0, 0]);
int[2] ooo2(bool b1, bool b2, bool b3, bool b4)
{
int x = 0;
if (b1 || x++ || b2 || !x++ || b3 || (b4 && x++))
{
return [x, 1];
}
else
{
return [x, 0];
}
}
static assert(ooo2(1, 0, 1, 0) == [0, 1]);
static assert(ooo2(0, 1, 1, 0) == [1, 1]);
static assert(ooo2(0, 0, 1, 0) == [2, 1]);
static assert(ooo2(0, 0, 0, 0) == [2, 0]);
//static assert(ooo2(0, 0, 0, 1) == [3, 1]); // oh god ...