[clang] [clang][Sema] Fix the continue and break scope for while loops (PR #152606)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 14 07:48:12 PDT 2025
Sirraide wrote:
@ojhunt FYI, I think would be easier to add an extra flag to the `Scope` class that basically keeps track of whether break/continue are currently allowed and only set that right before we start parsing the body. This would be different from the BreakScope/ContinueScope flags in that in e.g. `while(({ breka; true;})) {}`, we *do* want the enclosing `while` loop to be the parent `ContinueScope`—we just don’t want to actually allow `continue`/`break` in it yet.
So my suggestion would be to add that flag to Scope and then in `Sema::ActOnContinueStmt()` and `Sema::ActOnContinueStmt()`, we check if the parent continue/break scope has that flag set and issue a diagnostic if not.
I don’t think changes to codegen should be required at all since this refactor shouldn’t introduce any new valid code patterns—it should just disallow existing ones.
https://github.com/llvm/llvm-project/pull/152606
More information about the cfe-commits
mailing list