Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -9546,16 +9546,6 @@ void SliceExp::checkEscapeRef()
e1->checkEscapeRef();
}

int SliceExp::isLvalue()
{
return 1;
}

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

int SliceExp::checkModifiable(Scope *sc, int flag)
{
//printf("SliceExp::checkModifiable %s\n", toChars());
Expand Down
2 changes: 0 additions & 2 deletions src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,6 @@ struct SliceExp : UnaExp
void checkEscape();
void checkEscapeRef();
int checkModifiable(Scope *sc, int flag);
int isLvalue();
Expression *toLvalue(Scope *sc, Expression *e);
Expression *modifiableLvalue(Scope *sc, Expression *e);
int isBool(int result);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expand Down
29 changes: 14 additions & 15 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -5941,29 +5941,28 @@ MATCH TypeFunction::callMatch(Expression *ethis, Expressions *args, int flag)

// Non-lvalues do not match ref or out parameters
if (p->storageClass & STCref)
{ if (m && !arg->isLvalue())
{
Type *targb = targ->toBasetype();
Type *tprmb = tprm->toBasetype();
//printf("%s\n", targb->toChars());
//printf("%s\n", tprmb->toChars());

if (m && !arg->isLvalue())
{
Type *ta = targ->aliasthisOf();
if (arg->op == TOKstring && tprm->ty == Tsarray)
{ if (targ->ty != Tsarray)
targ = new TypeSArray(targ->nextOf(),
if (arg->op == TOKstring && tprmb->ty == Tsarray)
{ if (targb->ty != Tsarray)
targb = new TypeSArray(targb->nextOf(),
new IntegerExp(0, ((StringExp *)arg)->len,
Type::tindex));
}
else if (arg->op == TOKslice && tprmb->ty == Tsarray)
{ // Allow conversion from T[lwr .. upr] to ref T[upr-lwr]
targb = tprmb;
}
else
goto Nomatch;
}

Type *targb = targ->toBasetype();
Type *tprmb = tprm->toBasetype();
//printf("%s\n", targb->toChars());
//printf("%s\n", tprmb->toChars());

if (arg->op == TOKslice && tprmb->ty == Tsarray)
{ // Allow conversion from T[lwr .. upr] to ref T[upr-lwr]
targb = tprmb;
}

/* find most derived alias this type being matched.
*/
while (1)
Expand Down
9 changes: 7 additions & 2 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,9 +1592,14 @@ MATCH TemplateDeclaration::deduceFunctionTemplateMatch(Loc loc, Scope *sc, Objec
}

if (m && (fparam->storageClass & (STCref | STCauto)) == STCref)
{ if (!farg->isLvalue())
{
if (!farg->isLvalue())
{
goto Lnomatch;
if (farg->op == TOKslice && argtype->ty == Tsarray)
{ // Allow conversion from T[lwr .. upr] to ref T[upr-lwr]
}
else
goto Lnomatch;
}
}
if (m && (fparam->storageClass & STCout))
Expand Down
3 changes: 2 additions & 1 deletion test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,8 @@ struct Zadok
int bfg()
{
z[0] = 56;
fog(z[]) = [56, 6, 8];
auto zs = z[];
fog(zs) = [56, 6, 8];
assert(z[1] == 6);
assert(z[0] == 56);
return z[2];
Expand Down
18 changes: 9 additions & 9 deletions test/runnable/test12.d
Original file line number Diff line number Diff line change
Expand Up @@ -280,26 +280,26 @@ void test11()

struct Array12
{
char len;
void* p;
}
Array12 f12(string a)
{
return *cast(Array12*) &a[0..23]; //Internal error: ..\ztc\cgcs.c 350
char len;
void* p;
}
//Array12 f12(string a)
//{
// return *cast(Array12*) &a[0..23]; //Internal error: ..\ztc\cgcs.c 350
//}

Array12 g12(string a)
{
return *cast(Array12*) &a; //works
return *cast(Array12*) &a; //works
}

void test12()
{
string a = "12345678901234567890123";
Array12 b;

b = f12(a);
printf("b.len = %x\n", b.len);
//b = f12(a);
//printf("b.len = %x\n", b.len);
b = g12(a);
printf("b.len = %x\n", b.len);
}
Expand Down
24 changes: 24 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -3493,6 +3493,29 @@ void test155()
b = b >> i;
}

/***************************************************/
// 2486

void test2486()
{
void foo(ref int[] arr) {}

int[] arr = [1,2,3];
foo(arr); //OK
static assert(!__traits(compiles, foo(arr[1..2]))); // should be NG

struct S
{
int[] a;
auto ref opSlice(){ return a[]; } // line 4
}
S s;
s[];
// opSlice should return rvalue
static assert(is(typeof(&S.opSlice) == int[] function()));
static assert(!__traits(compiles, foo(s[]))); // should be NG
}

/***************************************************/
// 2521

Expand Down Expand Up @@ -5996,6 +6019,7 @@ int main()
test8442();
test86();
test87();
test2486();
test5554();
test88();
test7545();
Expand Down