This code should work.
class Class {}
bool test1()
{
Object c = new Class;
return typeid(c) is typeid(c);
}
static assert(test1() == true);
bool test2()
{
Object c = new Class;
Object o = new Object;
return typeid(c) is typeid(o);
}
static assert(test2() == false);
This is necessary for class object comparison in CTFE.
Comment #1 by k.hara.pg — 2013-03-09T06:29:20Z
Add more general test case, and change the summary.
----
bool test()
{
class Class {}
Object c = new Class;
Object o = new Object;
return c != o; // line 7
}
void main() { assert(test()); } // pass
static assert(test()); // line 10
output:
----
test.d(7): Error: opEquals cannot be interpreted at compile time, because it has no available source code
test.d(10): called from here: test()
test.d(10): while evaluating: static assert(test())
Comment #2 by clugdbug — 2013-03-11T04:10:21Z
*** This issue has been marked as a duplicate of issue 7151 ***