Bug 15780 – [REG2.069] CTFE foreach fails with tuple
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-09T10:17:00Z
Last change time
2016-11-04T09:04:54Z
Assigned to
nobody
Creator
jbc.engelen
Comments
Comment #0 by jbc.engelen — 2016-03-09T10:17:31Z
This code:
```
import std.typecons;
void foo(alias fields)() {
foreach(i, field; fields) {
enum string a = fields[i]; // OK
enum string b = field; // not OK with 2.069.2 ???
}
}
void main() {
foo!(tuple("H", "I", "J"))();
}
```
Builds with DMD 2.068.2.
Fails with DMD 2.069.2, and fails with DMD 2.070.2:
foreachTuple.d(6): Error: variable field cannot be read at compile time
foreachTuple.d(6): Error: variable field cannot be read at compile time
foreachTuple.d(6): Error: variable field cannot be read at compile time
foreachTuple.d(11): Error: template instance foreachTuple.foo!(Tuple("H", "I", "J")) error instantiating
I believe this is a regression.
(I am not sure if this is duplicate or related to https://issues.dlang.org/show_bug.cgi?id=15740 )
Comment #1 by greeenify — 2016-03-12T16:57:40Z
AFAIK foreach isn't implemented in phobos, but a feature of the compiler - so it seems to me to be an issue with dmd.