Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 635

Show
Ignore:
Timestamp:
08/28/10 03:51:12 (14 years ago)
Author:
walter
Message:

Issue 4652 - Compiler hangs on template with zero-length tuple and another argument

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/template.c

    r632 r635  
    948948    if (ethis) 
    949949    { 
    950950        for (size_t i = 0; i < parameters->dim; i++) 
    951951        {   TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; 
    952952            TemplateThisParameter *ttp = tp->isTemplateThisParameter(); 
    953953            if (ttp) 
    954954            {   MATCH m; 
    955955 
    956956                Type *t = new TypeIdentifier(0, ttp->ident); 
    957957                m = ethis->type->deduceType(paramscope, t, parameters, &dedtypes); 
    958958                if (!m) 
    959959                    goto Lnomatch; 
    960960                if (m < match) 
    961961                    match = m;          // pick worst match 
    962962            } 
    963963        } 
    964964    } 
    965965#endif 
    966966 
    967967    // Loop through the function parameters 
    968     for (i = 0; i < nfparams; i++) 
     968    for (size_t parami = 0; parami < nfparams; parami++) 
    969969    { 
    970970        /* Skip over function parameters which wound up 
    971971         * as part of a template tuple parameter. 
    972972         */ 
    973         if (i == fptupindex) 
    974         {   if (fptupindex == nfparams - 1) 
    975                 break; 
     973        if (parami == fptupindex) 
     974            continue; 
     975        /* Set i = index into function arguments 
     976         * Function parameters correspond to function arguments as follows. 
     977         * Note that tuple_dim may be zero, and there may be default or 
     978         * variadic arguments at the end. 
     979         *  arg [0..fptupindex] == param[0..fptupindex] 
     980         *  arg [fptupindex..fptupindex+tuple_dim] == param[fptupindex] 
     981         *  arg[fputupindex+dim.. ] == param[fptupindex+1.. ] 
     982         */ 
     983        i = parami; 
     984        if (fptupindex >= 0 && parami > fptupindex) 
    976985            i += tuple_dim - 1; 
    977             continue; 
    978         } 
    979  
    980         Parameter *fparam = Parameter::getNth(fparameters, i); 
     986 
     987        Parameter *fparam = Parameter::getNth(fparameters, parami); 
    981988 
    982989        if (i >= nfargs)                // if not enough arguments 
    983990        { 
    984991            if (fparam->defaultArg) 
    985992            {   /* Default arguments do not participate in template argument 
    986993                 * deduction. 
    987994                 */ 
    988995                goto Lmatch; 
    989996            } 
    990997        } 
    991998        else 
    992999        {   Expression *farg = (Expression *)fargs->data[i]; 
    9931000#if 0 
    9941001            printf("\tfarg->type   = %s\n", farg->type->toChars()); 
    9951002            printf("\tfparam->type = %s\n", fparam->type->toChars()); 
    9961003#endif 
    9971004            Type *argtype = farg->type; 
    9981005 
    9991006#if DMDV2 
    10001007            /* Allow string literals which are type [] to match with [dim] 
  • trunk/src/template.c

    r632 r635  
    10721072                mod |= MODconst; 
    10731073            if (stc & STCwild) 
    10741074                mod |= MODwild; 
    10751075            // Fix mod 
    10761076            if (mod & MODimmutable) 
    10771077                mod = MODimmutable; 
    10781078            if (mod & MODconst) 
    10791079                mod &= ~STCwild; 
    10801080            if (tthis->mod != mod) 
    10811081            { 
    10821082                if (!MODimplicitConv(tthis->mod, mod)) 
    10831083                    goto Lnomatch; 
    10841084                if (MATCHconst < match) 
    10851085                    match = MATCHconst; 
    10861086            } 
    10871087        } 
    10881088    } 
    10891089#endif 
    10901090 
    10911091    // Loop through the function parameters 
    1092     for (i = 0; i < nfparams; i++) 
     1092    for (size_t parami = 0; parami < nfparams; parami++) 
    10931093    { 
    10941094        /* Skip over function parameters which wound up 
    10951095         * as part of a template tuple parameter. 
    10961096         */ 
    1097         if (i == fptupindex) 
    1098         {   if (fptupindex == nfparams - 1) 
    1099                 break; 
     1097        if (parami == fptupindex) 
     1098            continue; 
     1099        /* Set i = index into function arguments 
     1100         * Function parameters correspond to function arguments as follows. 
     1101         * Note that tuple_dim may be zero, and there may be default or 
     1102         * variadic arguments at the end. 
     1103         *  arg [0..fptupindex] == param[0..fptupindex] 
     1104         *  arg [fptupindex..fptupindex+tuple_dim] == param[fptupindex] 
     1105         *  arg[fputupindex+dim.. ] == param[fptupindex+1.. ] 
     1106         */ 
     1107        i = parami; 
     1108        if (fptupindex >= 0 && parami > fptupindex) 
    11001109            i += tuple_dim - 1; 
    1101             continue; 
    1102         } 
    1103  
    1104         Parameter *fparam = Parameter::getNth(fparameters, i); 
     1110 
     1111        Parameter *fparam = Parameter::getNth(fparameters, parami); 
    11051112 
    11061113        if (i >= nfargs)                // if not enough arguments 
    11071114        { 
    11081115            if (fparam->defaultArg) 
    11091116            {   /* Default arguments do not participate in template argument 
    11101117                 * deduction. 
    11111118                 */ 
    11121119                goto Lmatch; 
    11131120            } 
    11141121        } 
    11151122        else 
    11161123        {   Expression *farg = (Expression *)fargs->data[i]; 
    11171124#if 0 
    11181125            printf("\tfarg->type   = %s\n", farg->type->toChars()); 
    11191126            printf("\tfparam->type = %s\n", fparam->type->toChars()); 
    11201127#endif 
    11211128            Type *argtype = farg->type; 
    11221129 
    11231130#if DMDV2 
    11241131            /* Allow string literals which are type [] to match with [dim]