Skip to content

Commit

Permalink
Error for auto ref without IFTI should not depend on the instantiatio…
Browse files Browse the repository at this point in the history
…n order
  • Loading branch information
9rnsr committed Jul 6, 2015
1 parent b4ee085 commit ec484e6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/template.c
Expand Up @@ -7736,19 +7736,22 @@ int TemplateInstance::compare(RootObject *o)
/* Template functions may have different instantiations based on
* "auto ref" parameters.
*/
if (fargs)
if (FuncDeclaration *fd = ti->toAlias()->isFuncDeclaration())
{
FuncDeclaration *fd = ti->toAlias()->isFuncDeclaration();
if (fd && !fd->errors)
if (!fd->errors)
{
Parameters *fparameters = fd->getParameters(NULL);
size_t nfparams = Parameter::dim(fparameters); // Num function parameters
for (size_t j = 0; j < nfparams && j < fargs->dim; j++)
size_t nfparams = Parameter::dim(fparameters); // Num function parameters
for (size_t j = 0; j < nfparams; j++)
{
Parameter *fparam = Parameter::getNth(fparameters, j);
Expression *farg = (*fargs)[j];
if (fparam->storageClass & STCautoref) // if "auto ref"
{
if (!fargs)
goto Lnotequals;
if (fargs->dim <= j)
break;
Expression *farg = (*fargs)[j];
if (farg->isLvalue())
{
if (!(fparam->storageClass & STCref))
Expand Down
25 changes: 25 additions & 0 deletions test/fail_compilation/fail14669.d
Expand Up @@ -16,3 +16,28 @@ void test1()
alias f1 = foo1!();
foo2(1);
}

/*
TEST_OUTPUT:
---
fail_compilation/fail14669.d(29): Error: 'auto' can only be used as the part of 'auto ref' for template function parameters
fail_compilation/fail14669.d(38): Error: template instance fail14669.bar1!int error instantiating
fail_compilation/fail14669.d(30): Error: 'auto' can only be used as the part of 'auto ref' for template function parameters
fail_compilation/fail14669.d(40): Error: template instance fail14669.bar2!int error instantiating
---
*/
void bar1(T)(auto ref T x) {}
void bar2(T)(auto ref T x) {}

void test2()
{
int n;

bar1(1);
bar1(n);
alias b1 = bar1!(int);

alias b2 = bar2!(int);
bar2(n);
bar2(1);
}

0 comments on commit ec484e6

Please sign in to comment.