Bug 1370 – Can't const-fold empty array literal

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-07-24T16:27:00Z
Last change time
2014-02-24T15:33:36Z
Keywords
rejects-valid
Assigned to
nobody
Creator
reiner.pope

Comments

Comment #0 by reiner.pope — 2007-07-24T16:27:47Z
The following code fails to compile, with error, "non-constant expression 1u ~ []" template GetArray(uint i) { static if (i == 0) const GetArray = 1u ~ GetArray!(i + 1); else const uint[] GetArray = []; } const uint[] array = GetArray!(0);
Comment #1 by samukha — 2007-07-28T05:31:33Z
There is a workaround, if it's of any use. template GetArray(uint i) { static if (i == 0) const GetArray = ([1u] ~ GetArray!(i + 1)); else const uint[] GetArray = []; } const uint[] array = GetArray!(0); ---------- One more test case. Fails with error "semicolon expected following auto declaration, not '~'". template GetArray(uint i) { static if (i == 0) const GetArray = [1u] ~ GetArray!(i + 1); //fails else const uint[] GetArray = []; } const uint[] array = GetArray!(0);
Comment #2 by yebblies — 2011-06-12T21:40:40Z
This works in current dmd 1.068 and 2.053.