Bug 16321 – ICE with delegate in UDA

Status
NEW
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-07-25T15:07:01Z
Last change time
2024-12-13T18:49:08Z
Keywords
ice
Assigned to
No Owner
Creator
Ketmar Dark
Moved to GitHub: dmd#19163 →

Comments

Comment #0 by ketmar — 2016-07-25T15:07:01Z
the following code gives Internal error: backend/cgcod.c 1666 in 2.071 and master: struct NameAttribute { int delegate () foo; } static NameAttribute getNamedAttribute(alias S) () { NameAttribute res; foreach (attr; __traits(getAttributes, S)) { static if (is(typeof(attr) == NameAttribute)) res = attr; } return res; } struct MyStruct { @NameAttribute({ return 42; }) int a; } void PrintAll(T) (T arg) { foreach (m; __traits(allMembers, T)) { enum nameAttr = getNamedAttribute!(__traits(getMember, T, m)); } } void main () { PrintAll(MyStruct()); }
Comment #1 by ketmar — 2016-07-25T15:09:57Z
and this gives segfault too, but different: enum nameAttr = __traits(getAttributes, (__traits(getMember, T, m)))[0]; writeln(nameAttr.foo()); Internal error: backend/cod4.c 3206
Comment #2 by dkorpel — 2022-09-29T14:56:50Z
Reduced a bit: ``` struct NameAttribute { int delegate() foo; } static NameAttribute getNamedAttribute(alias S)() { return __traits(getAttributes, S)[0]; } struct MyStruct { @NameAttribute({ return 42; }) int a; } void main() { MyStruct m; enum nameAttr = getNamedAttribute!(m.a); } ``` If you remove `static`, you get: ``` Error: need `this` for `getNamedAttribute` of type `pure nothrow @nogc @safe NameAttribute()` ```
Comment #3 by robert.schadek — 2024-12-13T18:49:08Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19163 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB