[Issue 20603] New: 'cannot use non-constant CTFE pointer in an initializer' in recursive structure with overlap
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 23 21:27:24 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20603
Issue ID: 20603
Summary: 'cannot use non-constant CTFE pointer in an
initializer' in recursive structure with overlap
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dkorpel at live.nl
This does not compile:
```
struct Base {
union {
int overlap;
immutable(Sub)* sub;
}
this(Sub) {
sub = new Sub;
}
}
struct Sub {
Base base;
}
immutable c0 = Base(Sub.init);
```
Error: cannot use non-constant CTFE pointer in an initializer Base(,
&Sub0(Base(0, __void)))
If you swap the order of the `overlap` and `sub` field, it compiles.
If you change the field in `Sub` to be of a different type than `Base`, it
compiles too.
The exact limitations of CTFE and pointers to the data segment are not clear to
me, but the above behavior is inconsistent and unclear.
--
More information about the Digitalmars-d-bugs
mailing list