Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[BUG] A for loop that uses a 'next' is not broken out of correctly when using 'break' #1436

Open
Labels
bugSomething isn't working

Description

Describe the bug
A Cpp2 for loop that uses 'next' is implemented as a do { } while(false) loop inside the main loop -- and the 'next' is done right after the do () while (false). And there's no special treatment for 'break' in that inner loop.

The consequence is that 'break' only breaks out of the do {} while (false) and not the actual loop.

To Reproduce
Steps to reproduce the behavior:
In this code at Compiler Explorer:

 myarray: std::array<i32, 4> = (0, 1, 2, 3);
 i := 0;
 for myarray next i++ do (member) {
 if member == 0 {
 break;
 }
 }
 std::cout << "i = " << i << std::endl;
 return i;
}

This should print "i = 1" but instead prints "i = 4".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /