Bug 1464 – "static" foreach breaks CTFE

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-08-31T10:28:00Z
Last change time
2015-06-09T01:14:15Z
Keywords
rejects-valid
Assigned to
bugzilla
Creator
reiner.pope

Comments

Comment #0 by reiner.pope — 2007-08-31T10:28:14Z
The following code gives compile-time error, "cannot evaluate gen() at compile time." Removing the "i" from the foreach fixes this. template Tuple(T...) { alias T val; } alias Tuple!(int) Tup; string gen() { foreach (i, type; Tup.val) { } return null; } string text = gen();
Comment #1 by someanon — 2007-08-31T17:05:24Z
BCS wrote: > [email protected] wrote: >> http://d.puremagic.com/issues/show_bug.cgi?id=1464 >> >> Summary: "static" foreach breaks CTFE >> Product: D >> Version: 2.003 >> Platform: PC >> OS/Version: Windows >> Status: NEW >> Keywords: rejects-valid >> Severity: normal >> Priority: P2 >> Component: DMD >> AssignedTo: [email protected] >> ReportedBy: [email protected] >> >> >> The following code gives compile-time error, "cannot evaluate gen() at >> compile >> time." Removing the "i" from the foreach fixes this. >> >> template Tuple(T...) >> { >> alias T val; >> } >> >> alias Tuple!(int) Tup; >> >> string gen() >> { >> foreach (i, type; Tup.val) >> { >> } >> return null; >> } >> >> string text = gen(); >> >> > > > That compiles at all? in the 1.x versions you can't have an alias of a > tuple in a template other than if the tuple name is the same as the name > of the template (It's a known bug, not a language restriction) It's aliasing the template instantiation, not the tuple. It should compile in 1.x as well as 2.x.
Comment #2 by bugzilla — 2007-09-28T22:16:57Z
Fixed dmd 1.021 and 2.004