Bug 7147 – [CTFE] typeid() should be supported in CTFE

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-12-21T05:38:27Z
Last change time
2024-12-13T17:57:14Z
Keywords
CTFE, rejects-valid
Assigned to
No Owner
Creator
Don
Blocks
7151
Moved to GitHub: dmd#18388 →

Comments

Comment #0 by clugdbug — 2011-12-21T05:38:27Z
static assert({ TypeInfo xxx = typeid(Object); TypeInfo yyy = typeid(new Error("xxx")); return true; }()); The first typeid gives: bug.d(7): Error: Cannot interpret & D17TypeInfo_C6Object6__initZ at compile time The second one gives: bug.d(38): Error: dereference of invalid pointer 'Error("xxx",null,0u,null,null,null)'
Comment #1 by bugzilla — 2013-04-17T14:00:26Z
Comment #2 by github-bugzilla — 2013-04-17T14:01:30Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/5d3aff1cc85b89bceaf09c5efa3174f1c823a0e0 Fix issue 7147 typeid() should be supported in CTFE Recognize the lowering which happens in the front-end, and change it to a reference to the static 'typeinfo' variable.
Comment #3 by r.sagitario — 2013-08-15T23:15:45Z
This code now raises an ICE: struct S { } static assert(typeid(S).init.length > 0); Assertion failure: 'thisval && thisval->op == TOKclassreference' on line 4067 in file 'interpret.c' If you use a class instead: class C {} static assert(typeid(C).init.length > 0); imp.d(2): Error: static assert (& D16TypeInfo_C3imp1C6__initZ.init.length > 0u) is not evaluatable at compile time
Comment #4 by nilsbossung — 2015-02-04T12:00:58Z
(In reply to Rainer Schuetze from comment #3) > struct S { } > static assert(typeid(S).init.length > 0); Now gives: "Error: static variable typeid(S) cannot be read at compile time". Same error when trying to call typeid(object.Object).opEquals: --- static assert(typeid(new Object).opEquals(typeid(new Object))); --- Error: static variable typeid(object.Object) cannot be read at compile time --- This blocks 7151. > class C {} > static assert(typeid(C).init.length > 0); Now gives: "Error: typeid(test.C).init is not yet implemented at compile time".
Comment #5 by robert.schadek — 2024-12-13T17:57:14Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18388 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB