www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3366] New: Crash by variadic member function templates

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3366

           Summary: Crash by variadic member function templates
           Product: D
           Version: 2.032
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rayerd.wiz gmail.com



PDT ---
 type ice.d
class A { void f(T...)() if (T.length != 1){} } void main() { A a = new A; a.f!int(); }
 dmd main 2> error.txt
// dmd crash
type error.txt
//ice.d(3): Error: template ice.A.f(T...) if (T.length != 1) declaration T is already defined -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 05 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3366


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |clugdbug yahoo.com.au
            Summary|Crash by variadic member    |Segfault(declaration.c)
                   |function templates          |variadic template with
                   |                            |unmatched constraint



Reduced test case:

void f(T...)() if (T.length > 20){}
void main(){
    f!(int, int)();
}

If the tuple length isn't used in the constraint, there's no ICE, but you get
the same silly error message about "T is already defined". It only happens if
the function has no parameters, and when there is no match.

It thinks T is already defined, because in the code which is patched below,
it's trying to pass an empty tuple for T. But it's already worked out what T
must be (in this case (int, int)). So it gets horribly confused.

Root cause: deduceFunctionTemplateMatch() missed this case.

PATCH:
template.c, deduceFunctionTemplateMatch(), line 885.
----------------
    /* Check for match of function arguments with variadic template
     * parameter, such as:
     *
     * template Foo(T, A...) { void Foo(T t, A a); }
     * void main() { Foo(1,2,3); }
     */
    if (tp)                // if variadic
    {
-    if (nfparams == 0)        // if no function parameters
+    if (nfparams == 0 && nfargs!=0)        // if no function parameters
    {
        Tuple *t = new Tuple();
        //printf("t = %p\n", t);
        dedargs->data[parameters->dim - 1] = (void *)t;
        declareParameter(paramscope, tp, t);
        goto L2;
    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 07 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3366


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



13:49:05 PDT ---
Fixed dmd 1.049 and 2.034

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