diff options
author | Steve Naroff <snaroff@apple.com> | 2008-01-21 23:53:58 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-01-21 23:53:58 +0000 |
commit | ca107309ffbcacae31d1685ab133f75ca0d7271a (patch) | |
tree | 914cd1ac086b0aa7fd226f83a9f168d77fec4614 | |
parent | 397cbf265369c914c3a58c124629bb1984104102 (diff) |
Sema::CheckInitializerTypes(). Start simpliying and cleaning up...
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46234 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Sema/SemaDecl.cpp | 12 | ||||
-rw-r--r-- | test/Sema/array-init.c | 5 |
2 files changed, 13 insertions, 4 deletions
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index b1753e1df4..44eb70b749 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -513,6 +513,13 @@ void Sema::CheckConstantInitList(QualType DeclType, InitListExpr *IList, bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType) { bool hadError = false; + // C99 6.7.8p3: The type of the entity to be initialized shall be an array + // of unknown size ("[]") or an object type that is not a variable array type. + if (const VariableArrayType *VAT = DeclType->getAsVariablyModifiedType()) + return Diag(VAT->getSizeExpr()->getLocStart(), + diag::err_variable_object_no_init, + VAT->getSizeExpr()->getSourceRange()); + InitListExpr *InitList = dyn_cast<InitListExpr>(Init); if (!InitList) { if (StringLiteral *strLiteral = dyn_cast<StringLiteral>(Init)) { @@ -550,10 +557,7 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType) { // C99 6.7.8p3: The type of the entity to be initialized shall be an array // of unknown size ("[]") or an object type that is not a variable array type. - if (const VariableArrayType *VAT = DeclType->getAsVariableArrayType()) { - if (const Expr *expr = VAT->getSizeExpr()) - return Diag(expr->getLocStart(), diag::err_variable_object_no_init, - expr->getSourceRange()); + if (const VariableArrayType *VAT = DeclType->getAsIncompleteArrayType()) { // We have a VariableArrayType with unknown size. Note that only the first // array can have unknown size. For example, "int [][]" is illegal. diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c index af4b04b725..60bb6afd9f 100644 --- a/test/Sema/array-init.c +++ b/test/Sema/array-init.c @@ -162,3 +162,8 @@ void charArrays() int i3[] = {}; //expected-error{{at least one initializer value required to size array}} expected-warning{{use of GNU empty initializer extension}} } +void variableArrayInit() { + int a = 4; + char strlit[a] = "foo"; //expected-error{{variable-sized object may not be initialized}} + int b[a] = { 1, 2, 4 }; //expected-error{{variable-sized object may not be initialized}} +} |