[clang] [clang][NFC] Use range-based for loop and algorithms in `SemaDeclCXX.cpp` (PR #169938)

David Stone via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 15 13:01:29 PST 2025


================
@@ -17658,21 +17637,20 @@ void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
       Expr::EvalResult Result;
       SmallString<12> ValueString;
       bool Print;
-    } DiagSide[2] = {{LHS, Expr::EvalResult(), {}, false},
-                     {RHS, Expr::EvalResult(), {}, false}};
-    for (unsigned I = 0; I < 2; I++) {
-      const Expr *Side = DiagSide[I].Cond;
+    } DiagSides[2] = {{LHS, Expr::EvalResult(), {}, false},
+                      {RHS, Expr::EvalResult(), {}, false}};
+    for (auto &DiagSide : DiagSides) {
----------------
davidstone wrote:

I don't think that would improve things. The names of the structured bindings would just match the name of the fields in the struct (in other words, I don't have a better local name than the name I'd get naturally). This means that structured bindings introduces the risk of naming them differently (leading to a bug caused by accidentally transposing the names) as well as a risk of someone updating the names in one place but not the other, causing them to go out of sync.

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


More information about the cfe-commits mailing list