-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][NFC] Use range-based for loops #96831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: None (MagentaTreehouse) ChangesUse range-based for loops. In addition, extracted a loop from Full diff: https://github.com/llvm/llvm-project/pull/96831.diff 1 Files Affected:
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();
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good overall, but I have minor suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Use range-based for loops. In addition, extracted a loop from `CXXRecordDecl::completeDefinition` to eliminate the `Done` flag, and only construct `MyFinalOverriders` when `FinalOverriders` is null.
Use range-based for loops. In addition, extracted a loop from `CXXRecordDecl::completeDefinition` to eliminate the `Done` flag, and only construct `MyFinalOverriders` when `FinalOverriders` is null.
Use range-based for loops. In addition, extracted a loop from
CXXRecordDecl::completeDefinition
to eliminate theDone
flag, and only constructMyFinalOverriders
whenFinalOverriders
is null.