[Issue 8018] New: Template fails to instantiate with templated argument

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 2 20:44:36 PDT 2012


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

           Summary: Template fails to instantiate with templated argument
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          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> 2012-05-02 20:45:48 PDT ---
version=Fail;

enum Enum { Foo }
struct Stub { }
template Temp(alias T) { alias Stub Temp; }

struct Foo
{
    auto call(Enum en)()
    {
        Stub arg;
        test!en(arg);
        return arg;
    }

    version(Fail)
    {
        void test(Enum en)(Temp!en arg)
            if (0) {}

        void test(Enum en)(Temp!en arg)
            if (1) {}
    }
    else
    version(Ok)
    {
        void test(Enum en)(Stub arg)
            if (0) {}

        void test(Enum en)(Stub arg)
            if (1) {}
    }
}

void main()
{
    Foo foo;
    foo.call!(Enum.Foo)();
}

This fails with:
test.d(14): Error: template test.Foo.test does not match any function template
declaration
test.d(14): Error: template test.Foo.test cannot deduce template function from
argument types !(cast(Enum)0)(Stub)
test.d(40): Error: template instance test.Foo.call!(cast(Enum)0) error
instantiating

You can comment out the test template in the version(Fail) that has this
constraint: "if (0) {}" and it will compile again.

You can also version=Fail to version=Ok then it will compile. The version=Ok
code doesn't instantiate the Temp template and this seems to work. But both
versions should work because both templates resolve the type as a Stub struct.

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