Skip to content

Commit

Permalink
fix Issue 11916 - [IFTI] Disabled by constraint overload with out w…
Browse files Browse the repository at this point in the history
…ith IFTI breaks overload resolution
  • Loading branch information
9rnsr committed Oct 26, 2014
1 parent 68e8c94 commit 868bc03
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
19 changes: 13 additions & 6 deletions src/template.c
Expand Up @@ -2299,9 +2299,7 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
MATCH mta = (MATCH)(x >> 4);
MATCH mfa = (MATCH)(x & 0xF);
//printf("match:t/f = %d/%d\n", mta, mfa);
if (!fd)
goto Lerror;
if (mfa == MATCHnomatch)
if (!fd || mfa == MATCHnomatch)
continue;

Type *tthis_fd = fd->needThis() ? tthis : NULL;
Expand Down Expand Up @@ -2581,14 +2579,23 @@ FuncDeclaration *TemplateDeclaration::doHeaderInstantiation(
tf->next = NULL;
fd->type = tf;
fd->type = fd->type->addSTC(scx->stc);

unsigned olderrors = global.startGagging();
fd->type = fd->type->semantic(fd->loc, scx);
scx = scx->pop();

if (global.endGagging(olderrors))
{
assert(fd->type->ty != Tfunction);
return NULL;
}
assert(fd->type->ty == Tfunction);

fd->originalType = fd->type; // for mangling
//printf("\t[%s] fd->type = %s, mod = %x, ", loc.toChars(), fd->type->toChars(), fd->type->mod);
//printf("fd->needThis() = %d\n", fd->needThis());

scx = scx->pop();

return fd->type->ty == Tfunction ? fd : NULL;
return fd;
}

bool TemplateDeclaration::hasStaticCtorOrDtor()
Expand Down
19 changes: 0 additions & 19 deletions test/fail_compilation/ice11857.d

This file was deleted.

30 changes: 30 additions & 0 deletions test/runnable/overload.d
Expand Up @@ -1008,6 +1008,35 @@ void test11785()
input.read(v);
}

/***************************************************/
// 11916

auto f11916(T)( T) { return 1; }
auto f11916(T)(out T) if (false) { return 2; }

auto g11916(T)( T) { return 1; }
auto g11916(T)(out T) { return 2; }

void test11916()
{
const int c = 1;
int m = 2;

// 'out const int' is invalid function parameter, so (out T) version will be dropped
// from overload candidates before template constraint evaluated.
assert(f11916(c) == 1);

// Both (T) and (out T) have valid signatures with T == int, but the 2nd overload will be
// dropped from overload candidates because of the template constraint.
assert(f11916(m) == 1);

// 'out const int' parameter is invalid, so non-out version is selected.
assert(g11916(c) == 1);

// MATCHconst for (T) version, and MATCHexact for (out T) version.
assert(g11916(m) == 2);
}

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

int main()
Expand Down Expand Up @@ -1039,6 +1068,7 @@ int main()
test10658a();
test10658b();
test11785();
test11916();

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

0 comments on commit 868bc03

Please sign in to comment.