mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 13:40:11 +03:00
pow: Ensure side effects are evaluated in e1^^0 rewrite
This commit is contained in:
parent
95fdc47f5f
commit
5c9c91a651
2 changed files with 22 additions and 3 deletions
|
@ -12818,11 +12818,10 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
|
||||||
result = ex;
|
result = ex;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Replace e1 ^^ 0 with 1
|
// Replace e1 ^^ 0 with (e1, 1)
|
||||||
else if (expo == 0)
|
else if (expo == 0)
|
||||||
{
|
{
|
||||||
Expression ex = one;
|
Expression ex = new CommaExp(exp.loc, pe.e1, one, exp);
|
||||||
ex.loc = exp.loc;
|
|
||||||
ex = ex.expressionSemantic(sc);
|
ex = ex.expressionSemantic(sc);
|
||||||
result = ex;
|
result = ex;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -35,10 +35,30 @@ void test3()
|
||||||
static assert(4.0 ^^ -1 == 0.25);
|
static assert(4.0 ^^ -1 == 0.25);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test4()
|
||||||
|
{
|
||||||
|
// Test that LHS side effects are evaluated.
|
||||||
|
int count = 0;
|
||||||
|
double x()
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
return 8.0;
|
||||||
|
}
|
||||||
|
assert(x ^^ -1 == 1.0 / 8.0);
|
||||||
|
assert(count == 1);
|
||||||
|
assert(x ^^ 0 == 1.0);
|
||||||
|
assert(count == 2);
|
||||||
|
assert(x ^^ 1 == 8.0);
|
||||||
|
assert(count == 3);
|
||||||
|
assert(x ^^ 2 == 64.0);
|
||||||
|
assert(count == 4);
|
||||||
|
}
|
||||||
|
|
||||||
extern(C) void main()
|
extern(C) void main()
|
||||||
{
|
{
|
||||||
test1();
|
test1();
|
||||||
test2();
|
test2();
|
||||||
test3();
|
test3();
|
||||||
|
test4();
|
||||||
printf("Success\n");
|
printf("Success\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue