[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 --- Comment #13 from Steven Schveighoffer --- (In reply to Imperatorn from comment #12) > Any update on this? What do you mean? It's resolved as invalid. The code no longer compiles (for a while now). --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 Imperatorn changed: What|Removed |Added CC||johan_forsberg_86@hotmail.c ||om --- Comment #12 from Imperatorn --- Any update on this? --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 LucienPe changed: What|Removed |Added Status|NEW |RESOLVED CC||lucien.perreg...@gmail.com Resolution|--- |INVALID --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 Sebchanged: What|Removed |Added CC||greensunn...@gmail.com --- Comment #11 from Seb --- FWIW this works with static foreach --- void main () { sformat(0, uint.max); } void sformat (Args...) (int index, Args args) { JT: switch (index) { static foreach (idx, unused; args) { case idx: assert(unused == args[idx], "Borken compiler"); break JT; } default: assert(0); } } --- https://run.dlang.io/is/eJvNFB --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 --- Comment #10 from Steven Schveighoffer--- *** Issue 17218 has been marked as a duplicate of this issue. *** --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 Alex Goltmanchanged: What|Removed |Added CC||alex.golt...@gmail.com --- Comment #9 from Alex Goltman --- looks like a duplicate of my issue https://issues.dlang.org/show_bug.cgi?id=17218 --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 --- Comment #8 from Steven Schveighoffer--- guys, the static foreach comment was a *wish* for this, not a recommendation to use some already existing thing. It would be nice to do: static foreach(idx; 0 .. args.length) Instead of the goofy "unused" symbol thing. In my code, I'm using Args, not args, so I have no idea why a variable for each tuple item should even need to be created. It might even be a type! Note that the "deprecation" is what I'm concerned about, as I have only this one way to make my switch statement out of a tuple (sorry Stefan, but string mixin is a *vastly inferior* option compared to this mechanism), and some future version of dmd I worry is going to flag this as an error, even though I never use the variable I didn't want to declare but was forced to. --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 --- Comment #7 from Nemanja Boric <4bur...@gmail.com> --- I'm not sure who ever got convinced by this code that `static foreach` works. This is just very helpful and clear approach, and it should grant `static foreach` becoming a real thing, because it is useful. While that is still not implemented, this code should work, as I see this as a bug/regression (https://github.com/rejectedsoftware/vibe.d/blob/6f37e694cc77063769bc4c9a42160627103e8354/web/vibe/web/rest.d#L1367 - yet another example, plus dozens on forums, etc). --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 --- Comment #6 from Stefan Koch--- Just because something is used in phobos does not it is correct. this code is highly dubious because it goats people into believing that tuple foreach actually works. The right way to do this is to build a string for the switch and mix it in. --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 Nemanja Boric <4bur...@gmail.com> changed: What|Removed |Added Keywords|accepts-invalid | --- Comment #5 from Nemanja Boric <4bur...@gmail.com> --- I don't agree that this code should error. This is a well known and common D idiom (simple GH search shows examples in Phobos, such: https://github.com/dlang/phobos/blob/master/std/algorithm/sorting.d#L1101), up to the point that there are also merged switch/foreach loops constructs where the label is applied to switch, so the `break` inside foreach would be considered switch break. --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 Stefan Kochchanged: What|Removed |Added Keywords||accepts-invalid CC||uplink.co...@gmail.com --- Comment #4 from Stefan Koch --- There is no such thing as static foreach. You are using tuple foreach which will force an unrolled loop. The provided code should error! --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 Steven Schveighofferchanged: What|Removed |Added CC||schvei...@yahoo.com --- Comment #3 from Steven Schveighoffer --- I see the same deprecation warning in my code, but I'm not using the actual tuple value, just the index. Static foreach would be handy here... --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 Nemanja Boric <4bur...@gmail.com> changed: What|Removed |Added CC||4bur...@gmail.com --- Comment #2 from Nemanja Boric <4bur...@gmail.com> --- I hit the same bug today: ``` import std.traits; struct S { int a, b, c, d, e, f; } void main() { S s; foreach (name; ["a", "b", "c"]) { switch (name) { foreach (i, ref field; s.tupleof) { case __traits(identifier, S.tupleof[i]): field = 0; // s.tupleof[i] = 0; works break; } default: break; } } } ``` --
[Issue 16521] Wrong code generation with switch + static foreach
https://issues.dlang.org/show_bug.cgi?id=16521 --- Comment #1 from Mathias Lang--- A bit of debugging proved that the following code is generated: ``` [{ enum ulong idx = 0; uint unused = _param_1; case idx: { assert(unused == args[idx], "Borken compiler"); break JT; } } ] ``` Note: Using `ref` results in the program segfaulting because it will then dereference an uninitialized `ref`. --