Bug 1768 – CTFE: cant ~= an array literal to an unitinitialized array
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-01-03T03:06:00Z
Last change time
2014-02-24T15:32:04Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2008-01-03T03:06:11Z
The bug is illustrated in case (c). Case (d) shows a workaround: explicitly initialize the array with [].
---------
char [] foo()
{
char [] a;
a ~="abc"; // ok
char [][] b;
b ~= "abc"; // ok
char [][][] c;
c ~= ["abc", "def"]; // Error: cannot eval at compile time
char [][][] d = [];
d ~= ["abc", "def"]; // ok
return "abc";
}
const xx = foo();
Comment #1 by gide — 2008-04-28T10:02:30Z
*** Bug 2009 has been marked as a duplicate of this bug. ***
Comment #2 by bugzilla — 2008-06-15T19:22:24Z
Works in dmd 1.030 and 2.014 (after replaceing all char[] with string).
Comment #3 by samukha — 2008-06-16T02:13:08Z
Please recheck. Both compilers fail for me. Other people was having the issue too.
dmd 1.030:
char [] foo()
{
char [][][] c;
c ~= ["abc", "def"]; // Error: cannot eval at compile time
return null;
}
const xx = foo();
dmd 2.014:
char [] foo()
{
string[][] c;
c ~= ["abc", "def"]; // Error: cannot eval at compile time
return null;
}
const xx = foo();
Comment #4 by samukha — 2008-06-17T10:09:10Z
While you are at it, please ensure that this works too:
(For dmd 1.030)
char[][] foo(char[][] a = null)
{
a ~= ["oops"];
return a;
}
static assert(foo()[0] == "oops");
Comment #5 by smjg — 2008-11-21T15:20:59Z
Cannot reproduce on 1.026 or 2.019. Is anyone else still seeing this problem?
Comment #6 by smjg — 2008-11-21T15:24:35Z
*** Bug 2009 has been marked as a duplicate of this bug. ***
Comment #7 by samukha — 2008-11-24T07:25:49Z
These seem to have been fixed except for the one with null as default argument but it's a different bug. And there are still bugs related to uninitialized arrays in structs.
Comment #8 by clugdbug — 2008-11-25T06:48:48Z
For what it's worth, I can also confirm that this is fixed.