diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-12-01 11:08:04 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-12-01 11:08:04 +0000 |
commit | 1569ce68681d909594d64f9b056d71f5dd7563bf (patch) | |
tree | 867cbbe32a66fd7d62dd9ce9df23a23fefdb8290 /lib/Sema/SemaInit.cpp | |
parent | f5bd02d290ff15268853e0456c130a1afa15e907 (diff) |
Notes
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r-- | lib/Sema/SemaInit.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 0f973d6d9ba3b..2eba704ff3a3c 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -136,8 +136,51 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, SourceLocation InitLoc, DeclarationName InitEntity, bool DirectInit) { if (DeclType->isDependentType() || - Init->isTypeDependent() || Init->isValueDependent()) + Init->isTypeDependent() || Init->isValueDependent()) { + // We have either a dependent type or a type- or value-dependent + // initializer, so we don't perform any additional checking at + // this point. + + // If the declaration is a non-dependent, incomplete array type + // that has an initializer, then its type will be completed once + // the initializer is instantiated. + if (!DeclType->isDependentType()) { + if (const IncompleteArrayType *ArrayT + = Context.getAsIncompleteArrayType(DeclType)) { + if (InitListExpr *ILE = dyn_cast<InitListExpr>(Init)) { + if (!ILE->isTypeDependent()) { + // Compute the constant array type from the length of the + // initializer list. + // FIXME: This will be wrong if there are designated + // initializations. Good thing they don't exist in C++! + llvm::APInt NumElements(Context.getTypeSize(Context.getSizeType()), + ILE->getNumInits()); + llvm::APInt Zero(Context.getTypeSize(Context.getSizeType()), 0); + if (NumElements == Zero) { + // Sizing an array implicitly to zero is not allowed by ISO C, + // but is supported by GNU. + Diag(ILE->getLocStart(), diag::ext_typecheck_zero_array_size); + } + + DeclType = Context.getConstantArrayType(ArrayT->getElementType(), + NumElements, + ArrayT->getSizeModifier(), + ArrayT->getIndexTypeCVRQualifiers()); + return false; + } + } + + // Make the array type-dependent by making it dependently-sized. + DeclType = Context.getDependentSizedArrayType(ArrayT->getElementType(), + /*NumElts=*/0, + ArrayT->getSizeModifier(), + ArrayT->getIndexTypeCVRQualifiers(), + SourceRange()); + } + } + return false; + } // C++ [dcl.init.ref]p1: // A variable declared to be a T& or T&&, that is "reference to type T" |