www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6574] New: Erroneous recursive call in template instantiation

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 puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



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: -------
Aug 29 2011