D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1790 - CTFE: foreach(Tuple) won't compile if Tuple contains string
Summary: CTFE: foreach(Tuple) won't compile if Tuple contains string
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2008-01-17 13:56 UTC by Don
Modified: 2014-02-24 15:33 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 Don 2008-01-17 13:56:43 UTC
Oddly, it compiles if you commment out the ; -- the foreach has to be non-empty. Behaviour is quite odd; if there are several items in the tuple, it will work if you don't use the whole tuple; eg Types[0..$-1] and Types[1..$] will work. So it sounds like some kind of memory corruption/unterminated string or similar.

Possibly the root cause of some of the bugs in issue 1298.

========
bug.d(9): Error: cannot evaluate foo() at compile time
---
int foo(Types...)() {
    foreach(T; Types) {
        ;   // will compile if you remove this line
    }
    return 0;
}

const int q = foo!("")();
Comment 1 Don 2009-02-03 08:18:08 UTC
This workaround for this bug has changed. On 1.039, it now fails even if you comment out the marked line. But it compiles if you add [] to the string.

int foo(Types...)() {
    foreach(T; Types) {
        ;
    }
    return 0;
}

const int q = foo!("abc"[])(); // OK
Comment 2 Walter Bright 2010-01-30 22:40:04 UTC
fixed dmd 1.056 and 2.040