From f349953367bcc880bc563c1f4db1086cfe8a0a32 Mon Sep 17 00:00:00 2001 From: k-hara Date: Tue, 23 Jun 2015 22:44:12 +0900 Subject: [PATCH] Error for auto ref without IFTI should not depend on the instantiation order --- src/template.c | 15 +++++++++------ test/fail_compilation/fail14669.d | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/template.c b/src/template.c index 70494054446a..f05d13442e8c 100644 --- a/src/template.c +++ b/src/template.c @@ -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)) diff --git a/test/fail_compilation/fail14669.d b/test/fail_compilation/fail14669.d index 1580ed645ddb..4cbfca6d5693 100644 --- a/test/fail_compilation/fail14669.d +++ b/test/fail_compilation/fail14669.d @@ -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); +}