Bug 1375 – CTFE fails for null strings and arrays

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-07-25T11:39:00Z
Last change time
2014-02-16T15:26:01Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
samukha

Comments

Comment #0 by samukha — 2007-07-25T11:39:46Z
Neither of the if's compile: int foo() { char[] s; if (s) { } if (s == null) { } if (s is null) { } if (s == "") { } if (s.length) { } return 0; } void main() { static x = foo(); } If s is initialized to a literal, only the last two if's compile successfully.
Comment #1 by smjg — 2007-07-25T20:21:42Z
When filing bugs, please include the error messages rather than merely stating that something doesn't compile. bz1375.d(30): Error: cannot evaluate foo() at compile time
Comment #2 by samukha — 2007-07-26T02:49:09Z
I wish the error message was informative enough to be worth writing. Anyway, thanks for pointing that out.
Comment #3 by wbaxter — 2008-07-02T00:08:28Z
Another example of probably same bug: char[] copy(char[] x) { char[] ret; foreach(c; x) { ret ~= c; } return ret; } pragma(msg, copy(``)); Error: test_ext.d(83): pragma msg string expected for message, not 'null' Can work around by changing char[] ret; to char[] ret = ``;
Comment #4 by clugdbug — 2009-01-07T08:32:44Z
This works for me in 1.039.
Comment #5 by clugdbug — 2009-04-06T03:02:02Z
This works in DMD2.027 and DMD1.042.