Bug 9671 – [CTFE] Class object cannot compare in compile time

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-09T02:39:00Z
Last change time
2013-03-11T04:10:21Z
Keywords
CTFE
Assigned to
nobody
Creator
k.hara.pg
Blocks
3789

Comments

Comment #0 by k.hara.pg — 2013-03-09T02:39:16Z
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 ***