D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7143 - [CTFE] cannot compare class references with "is"
Summary: [CTFE] cannot compare class references with "is"
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-20 06:58 UTC by Rainer Schuetze
Modified: 2011-12-21 15:24 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2011-12-20 06:58:20 UTC
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.