Skip to content

Commit

Permalink
Merge pull request #6893 from ibuclaw/issue17491
Browse files Browse the repository at this point in the history
fix Issue 17491 - Compiles on invalid: *&s.init.var is not an lvalue
  • Loading branch information
WalterBright committed Jun 14, 2017
2 parents 6ad2e6d + 84e6960 commit becedff
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ddmd/optimize.d
Expand Up @@ -1203,7 +1203,14 @@ extern (C++) Expression Expression_optimize(Expression e, int result, bool keepL
}

scope OptimizeVisitor v = new OptimizeVisitor(result, keepLvalue);
Expression ex = null;
v.ret = e;
e.accept(v);
return v.ret;

// Optimize the expression until it can no longer be simplified.
while (ex != v.ret)
{
ex = v.ret;
ex.accept(v);
}
return ex;
}
41 changes: 41 additions & 0 deletions test/fail_compilation/fail17491.d
@@ -0,0 +1,41 @@
/* TEST_OUTPUT:
---
fail_compilation/fail17491.d(24): Error: (S17491).init is not an lvalue
fail_compilation/fail17491.d(25): Error: S17491(0) is not an lvalue
fail_compilation/fail17491.d(27): Error: constant S17491(0).field is not an lvalue
fail_compilation/fail17491.d(28): Error: constant *&S17491(0).field is not an lvalue
fail_compilation/fail17491.d(33): Error: S17491(0) is not an lvalue
fail_compilation/fail17491.d(34): Error: S17491(0) is not an lvalue
fail_compilation/fail17491.d(36): Error: constant S17491(0).field is not an lvalue
fail_compilation/fail17491.d(37): Error: constant *&S17491(0).field is not an lvalue
---
*/

// https://issues.dlang.org/show_bug.cgi?id=17491

struct S17491
{
int field;
static int var;
}

void test17491()
{
S17491.init = S17491(42); // NG
*&S17491.init = S17491(42); // NG

S17491.init.field = 42; // NG
*&S17491.init.field = 42; // Should be NG

S17491.init.var = 42; // OK
*&S17491.init.var = 42; // OK

S17491(0) = S17491(42); // NG
*&S17491(0) = S17491(42); // NG

S17491(0).field = 42; // NG
*&S17491(0).field = 42; // Should be NG

S17491(0).var = 42; // OK
*&S17491(0).var = 42; // OK
}

0 comments on commit becedff

Please sign in to comment.