1375 – CTFE fails for null strings and arrays

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1375 - CTFE fails for null strings and arrays
Summary: CTFE fails for null strings and arrays
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 major
Assignee: Walter Bright
URL:
Keywords: rejects-valid
Depends on:
Blocks:
Reported: 2007年07月25日 11:39 UTC by Max Samukha
Modified: 2014年02月16日 15:26 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2007年07月25日 11:39:46 UTC
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 = ``;
Comment 4 Don 2009年01月07日 08:32:44 UTC
This works for me in 1.039.
Comment 5 Don 2009年04月06日 03:02:02 UTC
This works in DMD2.027 and DMD1.042.


AltStyle によって変換されたページ (->オリジナル) /