[Issue 1069] No error on type mismatch with varargs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Mar 19 21:28:31 PDT 2007


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


point14 at magma.ca changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |point14 at magma.ca




------- Comment #4 from point14 at magma.ca  2007-03-19 23:28 -------
I have expanded the example to show a bit more of the problem an end user can
have (sorry I have tango hard-coded, just replace with printf):

import tango.io.Stdout;

void another() {
  Stdout("Another one\n");
}

class C
{   
    this()
    {   
        add(&fn );     // Needed here
        add(another);  // Not needed here!!!!
    }

    void fn()
    {   
        Stdout( "hello\n" );
    }
}

class Elem
{   
    void delegate() proc;
    Elem next;
}

Elem first;

void add( void delegate()[] procs... )
{   
    foreach( p; procs )
    {   
        auto e = new Elem;
        e.proc = p;
        e.next = first;
        first = e;
    }
}

void call()
{   
    for( Elem e = first; e; e = e.next )
        e.proc();
}

void main()
{   
    auto val = new C;
    add(another);     // Not here!
    call();
}

This code works because by trial and error I have put the "&" in the right
places. Can this kind of segfault be avoided be detecting it at the compile
stage?

Regardless of the answer, I think a diagram (or more details) of what Frits
explains in the first reply would help me understand. Thanks.


-- 



More information about the Digitalmars-d-bugs mailing list