mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +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;
|
||||
return;
|
||||
}
|
||||
// Replace e1 ^^ 0 with 1
|
||||
// Replace e1 ^^ 0 with (e1, 1)
|
||||
else if (expo == 0)
|
||||
{
|
||||
Expression ex = one;
|
||||
ex.loc = exp.loc;
|
||||
Expression ex = new CommaExp(exp.loc, pe.e1, one, exp);
|
||||
ex = ex.expressionSemantic(sc);
|
||||
result = ex;
|
||||
return;
|
||||
|
|
|
@ -35,10 +35,30 @@ void test3()
|
|||
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()
|
||||
{
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
printf("Success\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue