[Issue 15741] New: A combination of union, pointer type parameter, and recursive call prevent CTFEability
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Mar 2 04:29:11 PST 2016
https://issues.dlang.org/show_bug.cgi?id=15741
Issue ID: 15741
Summary: A combination of union, pointer type parameter, and
recursive call prevent CTFEability
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ttanjo at gmail.com
In the following code, callBar(2) cannot be called at compile time but it
should.
I reproduce it with dmd v2.070-devel-03bce08 on Linux 64bit system and on
MacOSX system.
We can call callBar(1) instead of callBar(2) at compile time.
If we do not use recursive calls, it works.
If we use out parameter instead of pointer type parameter, it works.
---
struct Foo
{
union Store
{
string str;
Foo[int] object;
}
Store store;
}
void bar(Foo* value, int lv)
{
if (lv <= 0) return;
value.store.object = null;
Foo member;
bar(&member, lv-1);
value.store.object[lv] = member; // line 19
}
// for static assert
auto callBar(int a)
{
Foo f;
bar(&f, a);
return 0;
}
static assert(callBar(2) == 0);
---
Output:
error.d(19): Error: reinterpretation through overlapped field object is not
allowed in CTFE
error.d(18): called from here: bar(& member, lv - 1)
error.d(25): called from here: bar(& f, a)
error.d(29): called from here: callBar(2)
error.d(29): while evaluating: static assert(callBar(2) == 0)
This bug prevent std.json.parseJSON from being CTFEable for some inputs.
--
More information about the Digitalmars-d-bugs
mailing list