[Issue 6574] New: Erroneous recursive call in template instantiation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 29 19:49:11 PDT 2011


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

           Summary: Erroneous recursive call in template instantiation
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2011-08-29 19:49:09 PDT ---
For lack of a better name..

import std.stdio;

enum Method
{
    A,
    B,
}

void Foo(Method method = Method.A)()
{
    write("dispatch, ");
    Foo!method();
}

void Foo(Method method : Method.A)()
{
    writeln("Foo A");
}

void Foo(Method method : Method.B)()
{
    writeln("Foo B");
}

void main()
{
    Foo!();           // dispatch, Foo A
    Foo();            // dispatch, Foo A
}

That works. Now uncomment the first instantiation, the `Foo!()` part and
compile and run. The "dispatch" template instance keeps calling itself until
the stack is blown and the app exits.

What I was trying to do with code like the above was to use template
overloading with type specialization to switch between different types of
drawing methods. The default "dispatch" template is there in case the user
doesn't care which drawing method to use, the dispatch would then instantiate a
specialized template (one specialized for Method.A in this case).

But as you can see, this is buggy territory..

-- 
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