[clang] [Clang][Sema] Add -Wredundant-defer to diagnose redundant `_Defer`s (PR #225748)

Ambrose Leeb via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 23 06:52:22 PDT 2026


================
@@ -470,6 +470,23 @@ StmtResult Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R,
       DiagnoseEmptyLoopBody(Elts[i], Elts[i + 1]);
   }
 
+  // Find defer statements that immediately precede a break/continue statement.
+  std::optional<SourceLocation> DeferLoc = std::nullopt;
+  for (unsigned i = 0; i != NumElts; ++i) {
----------------
Sirraide wrote:

I feel like it’d be easier to just check if `i` is a defer statement and `i + 1` a break/continue statement (we could also check for `return` statements that don’t have a subexpression). In that case we also need to skip the check if `NumElts == 0`.

https://github.com/llvm/llvm-project/pull/225748


More information about the cfe-commits mailing list