Bug 17733 – idup fails for structs/classes with member functions
Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-08-08T16:23:00Z
Last change time
2017-08-08T18:49:04Z
Assigned to
nobody
Creator
fediushin.anton
Comments
Comment #0 by fediushin.anton — 2017-08-08T16:23:40Z
Test case:
void main() {
struct S {
void f() {}
}
[S()].idup;
}
Also, compilation fails only if struct is defined in same scope idup is called, so this code works just fine:
struct S {
void f() {}
}
void main() {
[S()].idup;
}
I've tested it with latest dmd, gdc and ldc
Comment #1 by schveiguy — 2017-08-08T18:49:04Z
This is because in the first case, S has a hidden context pointer to the stack frame of main().
If you mark it as a static struct, you will not have this problem.
Note that the ultimate reason it fails is because any items that have indirections cannot be implicitly converted to immutable.