Bug 8662 – Better error for duplicate labels inside static foreach body

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-14T18:53:25Z
Last change time
2023-07-28T08:36:43Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Andrej Mitrovic

Comments

Comment #0 by andrej.mitrovich — 2012-09-14T18:53:25Z
import std.traits; enum E { a, b } void main() { // static foreach foreach (x; EnumMembers!E) { Label: int y; } } test.d(12): Error: Label 'Label' already defined
Comment #1 by yebblies — 2013-11-24T06:27:48Z
That code is invalid, the foreach is unrolled to the following and there cannot be a single label to jump to. void main() { // static foreach { Label: int y; } { Label: int y; } } The error message should be fixed to explain that.
Comment #2 by mailnew4ster — 2013-11-24T06:40:51Z
Maybe append internal suffix to every label? e.g.: void main() { // static foreach foreach (x; EnumMembers!E) { goto Label; Label: int y; } } Will become: void main() { // static foreach { goto __Label_unroll_a_line_x_more_unique_info; __Label_unroll_a_line_x_more_unique_info: int y; } { goto __Label_unroll_b_line_y_more_unique_info; __Label_unroll_b_line_y_more_unique_info: int y; } }
Comment #3 by yebblies — 2013-11-24T06:51:11Z
Maybe.
Comment #4 by dlang-bot — 2023-07-27T19:58:08Z
@dkorpel created dlang/dmd pull request #15466 "Fix 8662 - Better error for duplicate labels inside static foreach body" fixing this issue: - Fix 8662 - Better error for duplicate labels inside static foreach body https://github.com/dlang/dmd/pull/15466
Comment #5 by dlang-bot — 2023-07-28T08:36:43Z
dlang/dmd pull request #15466 "Fix 8662 - Better error for duplicate labels inside static foreach body" was merged into master: - 815c3d9eb8ad665cf045f20c3c4f6452e1ea0cf4 by Dennis Korpel: Fix 8662 - Better error for duplicate labels inside static foreach body https://github.com/dlang/dmd/pull/15466