www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9671] New: Getting class object typeid in CTFE is not supported

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9671

           Summary: Getting class object typeid in CTFE is not supported
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: CTFE
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com
            Blocks: 3789



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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 09 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9671


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Getting class object typeid |[CTFE] Class object cannot
                   |in CTFE is not supported    |compare in compile time



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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 09 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9671


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 7151 ***

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