summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-05-26 20:19:07 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-05-26 20:19:07 +0000
commit1138ba669366ae749d487035c4bbec46a58db665 (patch)
tree015588f3bbca4a3983b48f61e6879589dd02f3df /clang/lib/Sema
parent1b08572a665402ce57771507b3bcbe235ff1ba82 (diff)
downloadbcm5719-llvm-1138ba669366ae749d487035c4bbec46a58db665.tar.gz
bcm5719-llvm-1138ba669366ae749d487035c4bbec46a58db665.zip
Fixes misc. flexible array bugs in c++ (PR7029).
llvm-svn: 104733
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp9
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp13
2 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 19e31da6ca4..dac070aaae8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6136,6 +6136,15 @@ void Sema::ActOnFields(Scope* S,
EnclosingDecl->setInvalidDecl();
continue;
}
+ if (!FD->getType()->isDependentType() &&
+ !Context.getBaseElementType(FD->getType())->isPODType()) {
+ Diag(FD->getLocation(), diag::err_flexible_array_has_nonpod_type)
+ << FD->getDeclName();
+ FD->setInvalidDecl();
+ EnclosingDecl->setInvalidDecl();
+ continue;
+ }
+
// Okay, we have a legal flexible array member at the end of the struct.
if (Record)
Record->setHasFlexibleArrayMember(true);
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 29fb6d6eac4..148d1463c20 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1892,9 +1892,15 @@ Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor,
// Fields.
for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
- E = ClassDecl->field_end(); Field != E; ++Field)
+ E = ClassDecl->field_end(); Field != E; ++Field) {
+ if ((*Field)->getType()->isIncompleteArrayType()) {
+ assert(ClassDecl->hasFlexibleArrayMember() &&
+ "Incomplete array type is not valid");
+ continue;
+ }
if (CollectFieldInitializer(Info, *Field, *Field))
HadError = true;
+ }
NumInitializers = Info.AllToInit.size();
if (NumInitializers > 0) {
@@ -4577,6 +4583,11 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
}
QualType FieldType = Field->getType().getNonReferenceType();
+ if (FieldType->isIncompleteArrayType()) {
+ assert(ClassDecl->hasFlexibleArrayMember() &&
+ "Incomplete array type is not valid");
+ continue;
+ }
// Build references to the field in the object we're copying from and to.
CXXScopeSpec SS; // Intentionally empty
OpenPOWER on IntegriCloud