Bug 15741 – A combination of union, pointer type parameter, and recursive call prevent CTFEability

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-03-02T12:29:11Z
Last change time
2024-12-13T18:47:01Z
Assigned to
No Owner
Creator
Tomoya Tanjo
Moved to GitHub: dmd#19102 →

Comments

Comment #0 by ttanjo — 2016-03-02T12:29:11Z
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.
Comment #1 by robert.schadek — 2024-12-13T18:47:01Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19102 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB