D issues are now
tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Summary: |
CTFE fails for null strings and arrays |
Product: |
D
|
Reporter: |
Max Samukha <samukha> |
Component: |
dmd | Assignee: |
Walter Bright <bugzilla> |
Status: |
RESOLVED
FIXED
|
Severity: |
major
|
CC: |
smjg
|
Priority: |
P2
|
Keywords: |
rejects-valid |
Version: |
D1 (retired) |
Hardware: |
x86 |
OS: |
Windows |
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
Stewart Gordon
2007年07月25日 20:21:42 UTC
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
Max Samukha
2007年07月26日 02:49:09 UTC
I wish the error message was informative enough to be worth writing. Anyway, thanks for pointing that out.
Comment 3
Bill Baxter
2008年07月02日 00:08:28 UTC
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 = ``;
This works for me in 1.039.
This works in DMD2.027 and DMD1.042.