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 Aug 30, 2015
1 parent 9779b69 commit fe4e163
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/dtemplate.d
Expand Up @@ -6267,19 +6267,22 @@ public:
/* Template functions may have different instantiations based on
* "auto ref" parameters.
*/
if (fargs)
if (auto 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++)
auto fparameters = fd.getParameters(null);
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 (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 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 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 fe4e163

Please sign in to comment.