D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6558 - [CTFE] UTF-decoding foreach gives wrong index (1-indexed)
Summary: [CTFE] UTF-decoding foreach gives wrong index (1-indexed)
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 major
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-08-26 11:04 UTC by Nick Sabalausky
Modified: 2011-09-01 12:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Nick Sabalausky 2011-08-26 11:04:43 UTC
int[] foo(string str)
{
	int[] ret;
	foreach(i, dchar c; str)
		ret ~= i;
		
	return ret;
}
pragma(msg, foo("Hi"));

Expected: [0,1]
Actual:   [1,2]

Among other likely problems, this causes stripLeft to give the wrong result at compile-time:

// Should fail, but currently passes:
static assert(stripLeft(" Hello") == "ello");
Comment 1 Nick Sabalausky 2011-08-26 11:06:52 UTC
Increasing priority since this is a wrong-code sort of issue.