aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-07-01 18:27:03 +0000
committerDouglas Gregor <dgregor@apple.com>2010-07-01 18:27:03 +0000
commit598a8543ec4c22e7f0a27e7ff2cf7e49cfa4e4ff (patch)
treef446384013d2195a51e329bb04789fc3588d74e5 /lib/Sema/SemaDeclCXX.cpp
parent4a0c26f57ffe685dfc795f04eaef9b805997b65e (diff)
Teach DeclareImplicitCopyConstructor how to cope with virtual bases
and multi-dimensional array fields. Fixes several bugs found by inspection. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107411 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--lib/Sema/SemaDeclCXX.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 4b7015caec..d710321939 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -4915,8 +4915,6 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor(Scope *S,
// If the class definition does not explicitly declare a copy
// constructor, one is declared implicitly.
- // FIXME: virtual bases!
-
// C++ [class.copy]p5:
// The implicitly-declared copy constructor for a class X will
// have the form
@@ -4933,6 +4931,20 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor(Scope *S,
BaseEnd = ClassDecl->bases_end();
HasConstCopyConstructor && Base != BaseEnd;
++Base) {
+ // Virtual bases are handled below.
+ if (Base->isVirtual())
+ continue;
+
+ const CXXRecordDecl *BaseClassDecl
+ = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
+ HasConstCopyConstructor
+ = BaseClassDecl->hasConstCopyConstructor(Context);
+ }
+
+ for (CXXRecordDecl::base_class_iterator Base = ClassDecl->vbases_begin(),
+ BaseEnd = ClassDecl->vbases_end();
+ HasConstCopyConstructor && Base != BaseEnd;
+ ++Base) {
const CXXRecordDecl *BaseClassDecl
= cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
HasConstCopyConstructor
@@ -4947,14 +4959,12 @@ CXXConstructorDecl *Sema::DeclareImplicitCopyConstructor(Scope *S,
FieldEnd = ClassDecl->field_end();
HasConstCopyConstructor && Field != FieldEnd;
++Field) {
- QualType FieldType = (*Field)->getType();
- if (const ArrayType *Array = Context.getAsArrayType(FieldType))
- FieldType = Array->getElementType();
+ QualType FieldType = Context.getBaseElementType((*Field)->getType());
if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) {
const CXXRecordDecl *FieldClassDecl
- = cast<CXXRecordDecl>(FieldClassType->getDecl());
+ = cast<CXXRecordDecl>(FieldClassType->getDecl());
HasConstCopyConstructor
- = FieldClassDecl->hasConstCopyConstructor(Context);
+ = FieldClassDecl->hasConstCopyConstructor(Context);
}
}