From 94f89154f92ec87161e0dc5f300877a57924f141 Mon Sep 17 00:00:00 2001 From: k-hara Date: Sun, 29 Mar 2015 13:46:10 +0900 Subject: [PATCH] fix Issue 14357 - Match on specType does not check the conflict with already deduced template arguments --- src/template.c | 22 +++++++++++++++++----- test/runnable/template9.d | 12 ++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/template.c b/src/template.c index 4a70ae1457ef..5d610222e29f 100644 --- a/src/template.c +++ b/src/template.c @@ -4774,7 +4774,7 @@ MATCH TemplateTypeParameter::matchArg(Scope *sc, RootObject *oarg, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam) { - //printf("TemplateTypeParameter::matchArg()\n"); + //printf("TemplateTypeParameter::matchArg('%s')\n", ident->toChars()); MATCH m = MATCHexact; Type *ta = isType(oarg); if (!ta) @@ -4800,7 +4800,19 @@ MATCH TemplateTypeParameter::matchArg(Scope *sc, RootObject *oarg, if (m2 < m) m = m2; if ((*dedtypes)[i]) - ta = (Type *)(*dedtypes)[i]; + { + Type *t = (Type *)(*dedtypes)[i]; + + if (dependent && !t->equals(ta)) // Bugzilla 14357 + goto Lnomatch; + + /* This is a self-dependent parameter. For example: + * template X(T : T*) {} + * template X(T : S!T, alias S) {} + */ + //printf("t = %s ta = %s\n", t->toChars(), ta->toChars()); + ta = t; + } } else { @@ -4991,7 +5003,7 @@ MATCH TemplateAliasParameter::matchArg(Scope *sc, RootObject *oarg, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam) { - //printf("TemplateAliasParameter::matchArg()\n"); + //printf("TemplateAliasParameter::matchArg('%s')\n", ident->toChars()); MATCH m = MATCHexact; Type *ta = isType(oarg); RootObject *sa = ta && !ta->deco ? NULL : getDsymbol(oarg); @@ -5241,7 +5253,7 @@ MATCH TemplateValueParameter::matchArg(Scope *sc, RootObject *oarg, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam) { - //printf("TemplateValueParameter::matchArg()\n"); + //printf("TemplateValueParameter::matchArg('%s')\n", ident->toChars()); MATCH m = MATCHexact; @@ -5468,7 +5480,7 @@ MATCH TemplateTupleParameter::matchArg(Scope *sc, RootObject *oarg, size_t i, TemplateParameters *parameters, Objects *dedtypes, Declaration **psparam) { - //printf("TemplateTupleParameter::matchArg()\n"); + //printf("TemplateTupleParameter::matchArg('%s')\n", ident->toChars()); Tuple *ovar = isTuple(oarg); if (!ovar) return MATCHnomatch; diff --git a/test/runnable/template9.d b/test/runnable/template9.d index 0024633926f8..94a05ebc037b 100644 --- a/test/runnable/template9.d +++ b/test/runnable/template9.d @@ -4399,6 +4399,18 @@ void test14174() accepter14174b(); // error } +/******************************************/ +// 14357 + +template Qux14357(T : U*, U : V*, V) +{ + pragma(msg, T); // no match <- float** + pragma(msg, U); // no match <- float* + pragma(msg, V); // no match <- int + enum Qux14357 = T.sizeof + V.sizeof; +} +static assert(!__traits(compiles, Qux14357!(float**, int*))); + /******************************************/ int main()