[Issue 10066] New: Template opEquals sometimes obstructs struct compilation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 12 01:12:16 PDT 2013


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

           Summary: Template opEquals sometimes obstructs struct
                    compilation
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2013-05-12 01:12:14 PDT ---
During debug for 10056, I found another bug case.

Following code will occur strange errors:
----
test.d(71): Error: static assert  "Cannot put a char[] into a
Appender!(string)"
test.d(39):        instantiated from here: put!(Appender!(string), char[])
test.d(30):        instantiated from here: Foo!(1)

code:
----
void main()
{
    alias Zoo = Foo!(1);
    Zoo z;
}

struct Foo(size_t N)
{
    string bar()
    {
        Appender!(string) w;
        char[] buf; put(w, buf);
        return "";
    }

    public bool opEquals(T)(T other) const
    // <--- Add const, different from bug 10056
    {
        alias Foo!(typeof(this), T, "CMP") P;
        return false;
    }
}

template Foo(T, U, string OP)
{
    static if (T.ISEMPTY && U.ISEMPTY)
        enum bool S = false;
    else
        enum bool S = false;

    alias Foo = Foo!(0);
}

void put(R, E)(ref R r, E e)
{
    static if (is(typeof(r.put(e))))
    {
        r.put(e);
    }
    else
    {
        static assert(false, "Cannot put a "~E.stringof~" into a "~R.stringof);
    }
}

struct Appender(A : T[], T)
{
    private template canPutItem(U)
    {
        enum bool canPutItem = is(U : T);
    }
    private template canPutRange(R)
    {
        enum bool canPutRange = is(typeof(Appender.init.put(R.init[0])));
    }

    void put(U)(U item) if (canPutItem!U)
    {
        char[T.sizeof == 1 ? 4 : 2] encoded;
        put(encoded[]);
    }
    void put(R)(R items) if (canPutRange!R)
    {
    }
}

The error occurs in the internal code generation for TypeInfo.equals. It
instantiates Foo's opEquals member template function in background, but the
instantiation errors are now unexpectedly un-gagged.

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