[clang] [clang][NFC] Use range-based for loops (PR #96831)

Mital Ashok via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 09:09:23 PDT 2024


================
@@ -2056,40 +2056,41 @@ void CXXRecordDecl::completeDefinition() {
   completeDefinition(nullptr);
 }
 
+static bool hasPureVirtualFinalOverrider(
+    const CXXRecordDecl &RD, const CXXFinalOverriderMap *FinalOverriders) {
+  auto ExistsIn = [](const CXXFinalOverriderMap &FinalOverriders) {
+    for (const CXXFinalOverriderMap::value_type &
+          OverridingMethodsEntry : FinalOverriders) {
+      for (const auto &[_, SubobjOverrides] : OverridingMethodsEntry.second) {
+        assert(SubobjOverrides.size() > 0 &&
+              "All virtual functions have overriding virtual functions");
+
+        if (SubobjOverrides.front().Method->isPureVirtual())
+          return true;
+      }
+    }
+    return false;
+  };
+
+  if (FinalOverriders)
+    return ExistsIn(*FinalOverriders);
+  CXXFinalOverriderMap MyFinalOverriders;
+  RD.getFinalOverriders(MyFinalOverriders);
+  return ExistsIn(MyFinalOverriders);
----------------
MitalAshok wrote:

Thoughts on moving this to the front like:

```c++
static bool hasPureVirtualFinalOverrider(
    const CXXRecordDecl &RD, const CXXFinalOverriderMap *FinalOverriders) {
  if (!FinalOverriders) {
    CXXFinalOverriderMap MyFinalOverriders;
    RD.getFinalOverriders(MyFinalOverriders);
    return hasPureVirtualFinalOverrider(RD, &MyFinalOverriders);
  }

  for (/*...*/) {
    // ...
  }
  return false;
}
```

?

This also gets rid of the lambda

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


More information about the cfe-commits mailing list