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

           Summary: [CTFE] cannot compare class references with "is"
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: r.sagita...@gmx.de


--- Comment #0 from Rainer Schuetze <r.sagita...@gmx.de> 2011-12-20 06:58:20 
PST ---
Comparing class references with null or other classes causes an error in CTFE,
e.g.:

module test;

class C 
{ 
    int x;
}

int getA()
{
    C c = new C;
    if(c is null)
        return -1;
    return c.x;
}

static assert(getA() == 0);


Compiling with "dmd -c test.d" yields:
test.d(11): Error: cannot compare C(0) at compile time
test.d(16):        called from here: getA()
test.d(16):        while evaluating: static assert(getA() == 0)

if you use "if(c)" instead of "if(c is null)", the error itself disappears,
there is only the call stack left:
test.d(16):        called from here: getA()
test.d(16):        while evaluating: static assert(getA() == 0)

Using "if(!c)" seems to work.

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

Reply via email to