Skip to content

Commit

Permalink
fix Issue 15781 - Template type deduction failure with same-type vari…
Browse files Browse the repository at this point in the history
…ables with different constness
  • Loading branch information
9rnsr committed Mar 15, 2016
1 parent bd4924b commit db7e4e1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/dcast.d
Expand Up @@ -2476,23 +2476,22 @@ extern (C++) bool isVoidArrayLiteral(Expression e, Type other)
// used by deduceType()
extern (C++) Type rawTypeMerge(Type t1, Type t2)
{
Type t1b = t1.toBasetype();
Type t2b = t2.toBasetype();

if (t1.equals(t2))
{
return t1;
}
else if (t1b.equals(t2b))
{
if (t1.equivalent(t2))
return t1.castMod(MODmerge(t1.mod, t2.mod));

auto t1b = t1.toBasetype();
auto t2b = t2.toBasetype();
if (t1b.equals(t2b))
return t1b;
}
else
{
TY ty = cast(TY)impcnvResult[t1b.ty][t2b.ty];
if (ty != Terror)
return Type.basic[ty];
}
if (t1b.equivalent(t2b))
return t1b.castMod(MODmerge(t1b.mod, t2b.mod));

auto ty = cast(TY)impcnvResult[t1b.ty][t2b.ty];
if (ty != Terror)
return Type.basic[ty];

return null;
}

Expand Down
23 changes: 23 additions & 0 deletions test/runnable/template9.d
Expand Up @@ -4757,6 +4757,29 @@ void test15352()
assert(is(typeof(s1) == typeof(s3)));
}

/******************************************/
// 15781

void test15781()
{
static struct S
{
int value;
}

T foo(T)(T a, T b)
{
return T();
}

const S cs;
S ms;
static assert(is(typeof(foo(ms, ms)) == S));
static assert(is(typeof(foo(ms, cs)) == const S));
static assert(is(typeof(foo(cs, ms)) == const S));
static assert(is(typeof(foo(cs, cs)) == const S));
}

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

int main()
Expand Down

0 comments on commit db7e4e1

Please sign in to comment.