[clang] [clang][NFC] Use range-based for loops (PR #96831)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 27 16:07:25 PDT 2024
https://github.com/MagentaTreehouse updated https://github.com/llvm/llvm-project/pull/96831
>From bdffd46532a1f4356f51b788aba6b9c52672d053 Mon Sep 17 00:00:00 2001
From: Mingyi Chen <cmingyi01 at gmail.com>
Date: Wed, 26 Jun 2024 19:21:27 -0400
Subject: [PATCH 1/2] [clang][NFC] Use range-based for loops
---
clang/lib/AST/DeclCXX.cpp | 64 +++++++++++++++++++--------------------
1 file changed, 32 insertions(+), 32 deletions(-)
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 7f2c786547b9b..18f2b76d9e781 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1521,11 +1521,11 @@ void CXXRecordDecl::setCaptures(ASTContext &Context,
auto *ToCapture = (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) *
Captures.size());
Data.AddCaptureList(Context, ToCapture);
- for (unsigned I = 0, N = Captures.size(); I != N; ++I) {
- if (Captures[I].isExplicit())
+ for (const LambdaCapture &C : Captures) {
+ if (C.isExplicit())
++Data.NumExplicitCaptures;
- new (ToCapture) LambdaCapture(Captures[I]);
+ new (ToCapture) LambdaCapture(C);
ToCapture++;
}
@@ -2056,40 +2056,40 @@ void CXXRecordDecl::completeDefinition() {
completeDefinition(nullptr);
}
+static bool hasPureVirtualFinalOverrider(
+ const CXXRecordDecl &RD, const CXXFinalOverriderMap *FinalOverriders) {
+ auto ExistsIn = [](const CXXFinalOverriderMap &FinalOverriders) {
+ for (const auto &[_, M] : FinalOverriders) {
+ for (const auto &[_, SO] : M) {
+ assert(SO.size() > 0 &&
+ "All virtual functions have overriding virtual functions");
+
+ if (SO.front().Method->isPureVirtual())
+ return true;
+ }
+ }
+ return false;
+ };
+
+ if (FinalOverriders)
+ return ExistsIn(*FinalOverriders);
+ CXXFinalOverriderMap MyFinalOverriders;
+ RD.getFinalOverriders(MyFinalOverriders);
+ return ExistsIn(MyFinalOverriders);
+}
+
void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) {
RecordDecl::completeDefinition();
// If the class may be abstract (but hasn't been marked as such), check for
// any pure final overriders.
- if (mayBeAbstract()) {
- CXXFinalOverriderMap MyFinalOverriders;
- if (!FinalOverriders) {
- getFinalOverriders(MyFinalOverriders);
- FinalOverriders = &MyFinalOverriders;
- }
-
- bool Done = false;
- for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(),
- MEnd = FinalOverriders->end();
- M != MEnd && !Done; ++M) {
- for (OverridingMethods::iterator SO = M->second.begin(),
- SOEnd = M->second.end();
- SO != SOEnd && !Done; ++SO) {
- assert(SO->second.size() > 0 &&
- "All virtual functions have overriding virtual functions");
-
- // C++ [class.abstract]p4:
- // A class is abstract if it contains or inherits at least one
- // pure virtual function for which the final overrider is pure
- // virtual.
- if (SO->second.front().Method->isPureVirtual()) {
- data().Abstract = true;
- Done = true;
- break;
- }
- }
- }
- }
+ //
+ // C++ [class.abstract]p4:
+ // A class is abstract if it contains or inherits at least one
+ // pure virtual function for which the final overrider is pure
+ // virtual.
+ if (mayBeAbstract() && hasPureVirtualFinalOverrider(*this, FinalOverriders))
+ markAbstract();
// Set access bits correctly on the directly-declared conversions.
for (conversion_iterator I = conversion_begin(), E = conversion_end();
>From ab4f537dd8bcdb5c3fff6049defd1eebd1da5cc7 Mon Sep 17 00:00:00 2001
From: Mingyi Chen <cmingyi01 at gmail.com>
Date: Thu, 27 Jun 2024 19:06:58 -0400
Subject: [PATCH 2/2] Use more descriptive names
---
clang/lib/AST/DeclCXX.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 18f2b76d9e781..ac266fe093e43 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2059,12 +2059,13 @@ void CXXRecordDecl::completeDefinition() {
static bool hasPureVirtualFinalOverrider(
const CXXRecordDecl &RD, const CXXFinalOverriderMap *FinalOverriders) {
auto ExistsIn = [](const CXXFinalOverriderMap &FinalOverriders) {
- for (const auto &[_, M] : FinalOverriders) {
- for (const auto &[_, SO] : M) {
- assert(SO.size() > 0 &&
+ 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 (SO.front().Method->isPureVirtual())
+ if (SubobjOverrides.front().Method->isPureVirtual())
return true;
}
}
More information about the cfe-commits
mailing list