Skip to content

Commit

Permalink
fix #20621 Comparing addresses of rvalue reference parameters not cor…
Browse files Browse the repository at this point in the history
…rect
  • Loading branch information
WalterBright committed Dec 30, 2024
1 parent da1b69a commit b939619
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion compiler/src/dmd/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ UnionExp Equal(EXP op, const ref Loc loc, Type type, Expression e1, Expression e

UnionExp Identity(EXP op, const ref Loc loc, Type type, Expression e1, Expression e2)
{
//printf("Identity %s %s\n", e1.toChars(), e2.toChars());
UnionExp ue = void;
int cmp;
if (e1.op == EXP.null_)
Expand All @@ -820,7 +821,17 @@ UnionExp Identity(EXP op, const ref Loc loc, Type type, Expression e1, Expressio
{
SymOffExp es1 = e1.isSymOffExp();
SymOffExp es2 = e2.isSymOffExp();
cmp = (es1.var == es2.var && es1.offset == es2.offset);
cmp = es1.offset == es2.offset;
if (cmp)
{
cmp = es1.var == es2.var;
if (!cmp && (es1.var.isParameter() || es2.var.isParameter()))
{
// because of ref's, they may still be the same, we cannot tell
cantExp(ue);
return ue;
}
}
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions compiler/test/runnable/rvalue1.d
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct S4
{
void* p;

this(ref S4) { }

this(S4 s)
{
assert(&s is &x); // confirm the rvalue reference
Expand Down

0 comments on commit b939619

Please sign in to comment.