Provide exception specifications for implicitly-declared copy constructors.

llvm-svn: 107429
This commit is contained in:
Douglas Gregor
2010-07-01 20:59:04 +00:00
parent 0e980755d3
commit 8453ddb5fe
3 changed files with 123 additions and 29 deletions

View File

@@ -159,6 +159,29 @@ bool CXXRecordDecl::hasConstCopyConstructor(ASTContext &Context) const {
return getCopyConstructor(Context, Qualifiers::Const) != 0;
}
/// \brief Perform a simplistic form of overload resolution that only considers
/// cv-qualifiers on a single parameter, and return the best overload candidate
/// (if there is one).
static CXXMethodDecl *
GetBestOverloadCandidateSimple(
const llvm::SmallVectorImpl<std::pair<CXXMethodDecl *, Qualifiers> > &Cands) {
if (Cands.empty())
return 0;
if (Cands.size() == 1)
return Cands[0].first;
unsigned Best = 0, N = Cands.size();
for (unsigned I = 1; I != N; ++I)
if (Cands[Best].second.isSupersetOf(Cands[I].second))
Best = I;
for (unsigned I = 1; I != N; ++I)
if (Cands[Best].second.isSupersetOf(Cands[I].second))
return 0;
return Cands[Best].first;
}
CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(ASTContext &Context,
unsigned TypeQuals) const{
QualType ClassType
@@ -167,6 +190,7 @@ CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(ASTContext &Context,
= Context.DeclarationNames.getCXXConstructorName(
Context.getCanonicalType(ClassType));
unsigned FoundTQs;
llvm::SmallVector<std::pair<CXXMethodDecl *, Qualifiers>, 4> Found;
DeclContext::lookup_const_iterator Con, ConEnd;
for (llvm::tie(Con, ConEnd) = this->lookup(ConstructorName);
Con != ConEnd; ++Con) {
@@ -175,14 +199,18 @@ CXXConstructorDecl *CXXRecordDecl::getCopyConstructor(ASTContext &Context,
if (isa<FunctionTemplateDecl>(*Con))
continue;
if (cast<CXXConstructorDecl>(*Con)->isCopyConstructor(FoundTQs)) {
CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(*Con);
if (Constructor->isCopyConstructor(FoundTQs)) {
if (((TypeQuals & Qualifiers::Const) == (FoundTQs & Qualifiers::Const)) ||
(!(TypeQuals & Qualifiers::Const) && (FoundTQs & Qualifiers::Const)))
return cast<CXXConstructorDecl>(*Con);
Found.push_back(std::make_pair(
const_cast<CXXConstructorDecl *>(Constructor),
Qualifiers::fromCVRMask(FoundTQs)));
}
}
return 0;
return cast_or_null<CXXConstructorDecl>(
GetBestOverloadCandidateSimple(Found));
}
bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context,
@@ -232,29 +260,6 @@ bool CXXRecordDecl::hasConstCopyAssignment(ASTContext &Context,
return false;
}
/// \brief Perform a simplistic form of overload resolution that only considers
/// cv-qualifiers on a single parameter, and return the best overload candidate
/// (if there is one).
static CXXMethodDecl *
GetBestOverloadCandidateSimple(
const llvm::SmallVectorImpl<std::pair<CXXMethodDecl *, Qualifiers> > &Cands) {
if (Cands.empty())
return 0;
if (Cands.size() == 1)
return Cands[0].first;
unsigned Best = 0, N = Cands.size();
for (unsigned I = 1; I != N; ++I)
if (Cands[Best].second.isSupersetOf(Cands[I].second))
Best = I;
for (unsigned I = 1; I != N; ++I)
if (Cands[Best].second.isSupersetOf(Cands[I].second))
return 0;
return Cands[Best].first;
}
CXXMethodDecl *CXXRecordDecl::getCopyAssignmentOperator(bool ArgIsConst) const {
ASTContext &Context = getASTContext();
QualType Class = Context.getTypeDeclType(const_cast<CXXRecordDecl *>(this));