@@ -17968,6 +17968,7 @@ void Sema::ActOnLastBitfield(SourceLocation DeclLoc,
17968
17968
AllIvarDecls.push_back(Ivar);
17969
17969
}
17970
17970
17971
+ namespace {
17971
17972
/// [class.dtor]p4:
17972
17973
/// At the end of the definition of a class, overload resolution is
17973
17974
/// performed among the prospective destructors declared in that class with
@@ -17976,7 +17977,7 @@ void Sema::ActOnLastBitfield(SourceLocation DeclLoc,
17976
17977
///
17977
17978
/// We do the overload resolution here, then mark the selected constructor in the AST.
17978
17979
/// Later CXXRecordDecl::getDestructor() will return the selected constructor.
17979
- static void ComputeSelectedDestructor(Sema &S, CXXRecordDecl *Record) {
17980
+ void ComputeSelectedDestructor(Sema &S, CXXRecordDecl *Record) {
17980
17981
if (!Record->hasUserDeclaredDestructor()) {
17981
17982
return;
17982
17983
}
@@ -18034,130 +18035,7 @@ static void ComputeSelectedDestructor(Sema &S, CXXRecordDecl *Record) {
18034
18035
Record->addedSelectedDestructor(dyn_cast<CXXDestructorDecl>(OCS.begin()->Function));
18035
18036
}
18036
18037
}
18037
-
18038
- /// [class.mem.special]p5
18039
- /// Two special member functions are of the same kind if:
18040
- /// - they are both default constructors,
18041
- /// - they are both copy or move constructors with the same first parameter
18042
- /// type, or
18043
- /// - they are both copy or move assignment operators with the same first
18044
- /// parameter type and the same cv-qualifiers and ref-qualifier, if any.
18045
- static bool AreSpecialMemberFunctionsSameKind(ASTContext &Context,
18046
- CXXMethodDecl *M1,
18047
- CXXMethodDecl *M2,
18048
- Sema::CXXSpecialMember CSM) {
18049
- if (CSM == Sema::CXXDefaultConstructor)
18050
- return true;
18051
- if (!Context.hasSameType(M1->getParamDecl(0)->getType(),
18052
- M2->getParamDecl(0)->getType()))
18053
- return false;
18054
- if (!Context.hasSameType(M1->getThisType(), M2->getThisType()))
18055
- return false;
18056
-
18057
- return true;
18058
- }
18059
-
18060
- /// [class.mem.special]p6:
18061
- /// An eligible special member function is a special member function for which:
18062
- /// - the function is not deleted,
18063
- /// - the associated constraints, if any, are satisfied, and
18064
- /// - no special member function of the same kind whose associated constraints
18065
- /// [CWG2595], if any, are satisfied is more constrained.
18066
- static void SetEligibleMethods(Sema &S, CXXRecordDecl *Record,
18067
- ArrayRef<CXXMethodDecl *> Methods,
18068
- Sema::CXXSpecialMember CSM) {
18069
- SmallVector<bool, 4> SatisfactionStatus;
18070
-
18071
- for (CXXMethodDecl *Method : Methods) {
18072
- const Expr *Constraints = Method->getTrailingRequiresClause();
18073
- if (!Constraints)
18074
- SatisfactionStatus.push_back(true);
18075
- else {
18076
- ConstraintSatisfaction Satisfaction;
18077
- if (S.CheckFunctionConstraints(Method, Satisfaction))
18078
- SatisfactionStatus.push_back(false);
18079
- else
18080
- SatisfactionStatus.push_back(Satisfaction.IsSatisfied);
18081
- }
18082
- }
18083
-
18084
- for (size_t i = 0; i < Methods.size(); i++) {
18085
- if (!SatisfactionStatus[i])
18086
- continue;
18087
- CXXMethodDecl *Method = Methods[i];
18088
- const Expr *Constraints = Method->getTrailingRequiresClause();
18089
- bool AnotherMethodIsMoreConstrained = false;
18090
- for (size_t j = 0; j < Methods.size(); j++) {
18091
- if (i == j || !SatisfactionStatus[j])
18092
- continue;
18093
- CXXMethodDecl *OtherMethod = Methods[j];
18094
- if (!AreSpecialMemberFunctionsSameKind(S.Context, Method, OtherMethod,
18095
- CSM))
18096
- continue;
18097
-
18098
- const Expr *OtherConstraints = OtherMethod->getTrailingRequiresClause();
18099
- if (!OtherConstraints)
18100
- continue;
18101
- if (!Constraints) {
18102
- AnotherMethodIsMoreConstrained = true;
18103
- break;
18104
- }
18105
- if (S.IsAtLeastAsConstrained(OtherMethod, {OtherConstraints}, Method,
18106
- {Constraints},
18107
- AnotherMethodIsMoreConstrained)) {
18108
- // There was an error with the constraints comparison. Exit the loop
18109
- // and don't consider this function eligible.
18110
- AnotherMethodIsMoreConstrained = true;
18111
- }
18112
- if (AnotherMethodIsMoreConstrained)
18113
- break;
18114
- }
18115
- // FIXME: Do not consider deleted methods as eligible after implementing
18116
- // DR1734 and DR1496.
18117
- if (!AnotherMethodIsMoreConstrained) {
18118
- Method->setIneligibleOrNotSelected(false);
18119
- Record->addedEligibleSpecialMemberFunction(Method, 1 << CSM);
18120
- }
18121
- }
18122
- }
18123
-
18124
- static void ComputeSpecialMemberFunctionsEligiblity(Sema &S,
18125
- CXXRecordDecl *Record) {
18126
- SmallVector<CXXMethodDecl *, 4> DefaultConstructors;
18127
- SmallVector<CXXMethodDecl *, 4> CopyConstructors;
18128
- SmallVector<CXXMethodDecl *, 4> MoveConstructors;
18129
- SmallVector<CXXMethodDecl *, 4> CopyAssignmentOperators;
18130
- SmallVector<CXXMethodDecl *, 4> MoveAssignmentOperators;
18131
-
18132
- for (auto *Decl : Record->decls()) {
18133
- auto *MD = dyn_cast<CXXMethodDecl>(Decl);
18134
- if (!MD)
18135
- continue;
18136
- if (auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
18137
- if (CD->isInvalidDecl())
18138
- continue;
18139
- if (CD->isDefaultConstructor())
18140
- DefaultConstructors.push_back(MD);
18141
- else if (CD->isCopyConstructor())
18142
- CopyConstructors.push_back(MD);
18143
- else if (CD->isMoveConstructor())
18144
- MoveConstructors.push_back(MD);
18145
- } else if (MD->isCopyAssignmentOperator()) {
18146
- CopyAssignmentOperators.push_back(MD);
18147
- } else if (MD->isMoveAssignmentOperator()) {
18148
- MoveAssignmentOperators.push_back(MD);
18149
- }
18150
- }
18151
-
18152
- SetEligibleMethods(S, Record, DefaultConstructors,
18153
- Sema::CXXDefaultConstructor);
18154
- SetEligibleMethods(S, Record, CopyConstructors, Sema::CXXCopyConstructor);
18155
- SetEligibleMethods(S, Record, MoveConstructors, Sema::CXXMoveConstructor);
18156
- SetEligibleMethods(S, Record, CopyAssignmentOperators,
18157
- Sema::CXXCopyAssignment);
18158
- SetEligibleMethods(S, Record, MoveAssignmentOperators,
18159
- Sema::CXXMoveAssignment);
18160
- }
18038
+ } // namespace
18161
18039
18162
18040
void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
18163
18041
ArrayRef<Decl *> Fields, SourceLocation LBrac,
@@ -18185,6 +18063,9 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
18185
18063
RecordDecl *Record = dyn_cast<RecordDecl>(EnclosingDecl);
18186
18064
CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(EnclosingDecl);
18187
18065
18066
+ if (CXXRecord && !CXXRecord->isDependentType())
18067
+ ComputeSelectedDestructor(*this, CXXRecord);
18068
+
18188
18069
// Start counting up the number of named members; make sure to include
18189
18070
// members of anonymous structs and unions in the total.
18190
18071
unsigned NumNamedMembers = 0;
@@ -18470,8 +18351,6 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
18470
18351
Completed = true;
18471
18352
}
18472
18353
}
18473
- ComputeSelectedDestructor(*this, CXXRecord);
18474
- ComputeSpecialMemberFunctionsEligiblity(*this, CXXRecord);
18475
18354
}
18476
18355
}
18477
18356
0 commit comments