Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wilson committed Feb 21, 2012
2 parents bf328e4 + 53fc296 commit 44e96eb
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 20 deletions.
20 changes: 5 additions & 15 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -3944,19 +3944,6 @@ int StructLiteralExp::getFieldIndex(Type *type, unsigned offset)
return -1;
}

#if DMDV2
int StructLiteralExp::isLvalue()
{
return 1;
}
#endif

Expression *StructLiteralExp::toLvalue(Scope *sc, Expression *e)
{
return this;
}


void StructLiteralExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writestring(sd->toChars());
Expand Down Expand Up @@ -8017,11 +8004,14 @@ Expression *CallExp::semantic(Scope *sc)
#if DMDV2
int CallExp::isLvalue()
{
// if (type->toBasetype()->ty == Tstruct)
// return 1;
Type *tb = e1->type->toBasetype();
if (tb->ty == Tfunction && ((TypeFunction *)tb)->isref)
{
if (e1->op == TOKdotvar)
if (((DotVarExp *)e1)->var->isCtorDeclaration())
return 0;
return 1; // function returns a reference
}
return 0;
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,6 @@ struct StructLiteralExp : Expression
Expression *optimize(int result);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
dt_t **toDt(dt_t **pdt);
int isLvalue();
Expression *toLvalue(Scope *sc, Expression *e);
MATCH implicitConvTo(Type *t);

int inlineCost3(InlineCostState *ics);
Expand Down
2 changes: 1 addition & 1 deletion src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,7 @@ MATCH FuncDeclaration::leastAsSpecialized(FuncDeclaration *g)
e->type = p->type;
}
else
e = p->type->defaultInit();
e = p->type->defaultInitLiteral(0);
args.tdata()[u] = e;
}

Expand Down
3 changes: 2 additions & 1 deletion test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,8 @@ void bar5258(int n, ref Foo5258 fong) {
fong.x++;
}
int bug5258() {
bar5258(1, Foo5258());
Foo5258 foo5258 = Foo5258();
bar5258(1, foo5258);
return 45;
}
static assert(bug5258()==45);
Expand Down
5 changes: 4 additions & 1 deletion test/compilable/line.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ int #line 10
x;

static assert(__LINE__ == 12);
static assert(__FILE__ == "compilable/line.d");
version(Windows)
static assert(__FILE__ == "compilable\\line.d");
else
static assert(__FILE__ == "compilable/line.d");

#line 100 "newfile.d"

Expand Down
58 changes: 58 additions & 0 deletions test/runnable/structlit.d
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,63 @@ void test5885()
assert(a == b);
}

/********************************************/
// 5889

struct S5889a { int n; }
struct S5889b { this(int n){} }

bool isLvalue(S)(auto ref S s){ return __traits(isRef, s); }

int foo(ref S5889a s) { return 1; }
int foo( S5889a s) { return 2; }
int foo(ref S5889b s) { return 1; }
int foo( S5889b s) { return 2; }

int goo(ref const(S5889a) s) { return 1; }
int goo( const(S5889a) s) { return 2; }
int goo(ref const(S5889b) s) { return 1; }
int goo( const(S5889b) s) { return 2; }

int too(S)(ref S s) { return 1; }
int too(S)( S s) { return 2; }

S makeRvalue(S)(){ S s; return s; }

void test5889()
{
S5889a sa;
S5889b sb;

assert( isLvalue(sa));
assert( isLvalue(sb));
assert(!isLvalue(S5889a(0)));
assert(!isLvalue(S5889b(0)));
assert(!isLvalue(makeRvalue!S5889a()));
assert(!isLvalue(makeRvalue!S5889b()));

assert(foo(sa) == 1);
assert(foo(sb) == 1);
assert(foo(S5889a(0)) == 2);
assert(foo(S5889b(0)) == 2);
assert(foo(makeRvalue!S5889a()) == 2);
assert(foo(makeRvalue!S5889b()) == 2);

assert(goo(sa) == 1);
assert(goo(sb) == 1);
assert(goo(S5889a(0)) == 2);
assert(goo(S5889b(0)) == 2);
assert(goo(makeRvalue!S5889a()) == 2);
assert(goo(makeRvalue!S5889b()) == 2);

assert(too(sa) == 1);
assert(too(sb) == 1);
assert(too(S5889a(0)) == 2);
assert(too(S5889b(0)) == 2);
assert(too(makeRvalue!S5889a()) == 2);
assert(too(makeRvalue!S5889b()) == 2);
}

/********************************************/

int main()
Expand All @@ -385,6 +442,7 @@ int main()
test13();
test3198and1914();
test5885();
test5889();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 44e96eb

Please sign in to comment.