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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 19 04:30:18 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4652



--- Comment #5 from Don <clugdbug at yahoo.com.au> 2010-08-19 04:30:12 PDT ---
That patch was incorrect, it failed to deal with default and variadic
parameters. This new test case incorporates the test case from bug 4676 as
well,
which is also fixed by this patch.
---
void bug4652(U, T...)(long y, T x, U num){}
void bug4652default(T) (T value, int x=2) {}
void bug4652default(T) (T value, int y){ }
void bug4676(T...)(T args, string str) {}
void bug4676(T...)(T args) {}
void instantiate4652()
{
    bug4652(2, 'c', 27, 'e', 'f',1); // rejects-valid
    bug4652(2, 1);  // infinite loop on valid code
    bug4652default(true);
    bug4676(1, 2, 3);
}
---


Revised patch. Template.c, line 1090, deduceFunctionTemplateMatch().
==========================

 #endif

     // Loop through the function parameters
-    for (i = 0; i < nfparams; i++)
+    for (size_t parami = 0; parami < nfparams; parami++)
     {
         /* Skip over function parameters which wound up
          * as part of a template tuple parameter.
          */
-        if (i == fptupindex)
-        {   if (fptupindex == nfparams - 1)
-                break;
+        if (parami == fptupindex)
+            continue;
+        /* Set i = index into function arguments           
+         * Function parameters correspond to function arguments as follows.
+         * Note that tuple_dim may be zero, and there may be default or 
+         * variadic arguments at the end.
+         *  arg [0..fptupindex] == param[0..fptupindex]
+         *  arg [fptupindex..fptupindex+tuple_dim] == param[fptupindex]
+         *  arg[fputupindex+dim.. ] == param[fptupindex+1.. ]
+         */
+        i = parami;
+        if (fptupindex >= 0 && parami > fptupindex)
             i += tuple_dim - 1;
-            continue;
-        }

-        Parameter *fparam = Parameter::getNth(fparameters, i);
+        Parameter *fparam = Parameter::getNth(fparameters, parami);

         if (i >= nfargs)                // if not enough arguments
         {

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list