[clang] [clang][NFC] Use range-based for loops (PR #96831)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 28 13:58:27 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/3] [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/3] 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;
}
}
>From 104aff411706201b0efd65e38940a3a1d68b9f9c Mon Sep 17 00:00:00 2001
From: Mingyi Chen <cmingyi01 at gmail.com>
Date: Fri, 28 Jun 2024 16:57:57 -0400
Subject: [PATCH 3/3] Move null check to the front
---
clang/lib/AST/DeclCXX.cpp | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index ac266fe093e43..d5c140fd34389 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -2058,25 +2058,23 @@ void CXXRecordDecl::completeDefinition() {
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) {
+ CXXFinalOverriderMap MyFinalOverriders;
+ RD.getFinalOverriders(MyFinalOverriders);
+ return hasPureVirtualFinalOverrider(RD, &MyFinalOverriders);
+ }
+
+ 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 (FinalOverriders)
- return ExistsIn(*FinalOverriders);
- CXXFinalOverriderMap MyFinalOverriders;
- RD.getFinalOverriders(MyFinalOverriders);
- return ExistsIn(MyFinalOverriders);
+ if (SubobjOverrides.front().Method->isPureVirtual())
+ return true;
+ }
+ }
+ return false;
}
void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) {
More information about the cfe-commits
mailing list