Bug 2376 – CTFE fails on array literal of array literals of chars
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-09-27T06:10:00Z
Last change time
2015-06-09T01:20:17Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
samukha
Comments
Comment #0 by samukha — 2008-09-27T06:10:52Z
string foo(string[] ss)
{
string r;
r ~= ss[0]; // problem here
return r;
}
enum r = foo([['c'], ['d']]);
----
cannot evaluate foo([['c'],['d']]) at compile time
Comment #1 by samukha — 2008-09-27T06:57:00Z
This applies to any array of arrays, not only chars. To workaround, initialize r in foo to []:
string foo(string[] ss)
{
string r = []; // Interestingly, "" doesn't work.
r ~= ss[0];
return r;
}
enum r = foo([['c'], ['d']]);
However, the result of foo is crippled in a way that it cannot be processed further at compile time.
For example, pragma(msg, r) fails with Error: string expected for message, not '['c']'
The bug is also present in dmd 1.
Comment #2 by matti.niemenmaa+dbugzilla — 2008-09-27T11:11:10Z
This one's probably related to, if not a duplicate of, Issue 1059.
Comment #3 by bugzilla — 2008-10-04T01:31:16Z
Please file pragma(msg, ['c']) as a separate report.