www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8018] New: Template fails to instantiate with templated argument

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



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: -------
May 02 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8018




20:48:16 PDT ---
Ok there's another workaround, just make the last type implicit:

void test(Enum en, StubType)(StubType arg)

So maybe it's not a major bug. :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 02 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8018


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME



14:31:32 PDT ---
Works in 2.063.2.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 17 2013