summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-01-18 20:40:52 +0000
committerSteve Naroff <snaroff@apple.com>2008-01-18 20:40:52 +0000
commitacb6fa6bea2dfcbe5b4e327e0b75d021b98078c4 (patch)
tree52d74bc3fc6d9f236a985cb9bbed12a871400e0b /clang
parent5c94cb35966482e3966735e7fa2018cd5fd42286 (diff)
downloadbcm5719-llvm-acb6fa6bea2dfcbe5b4e327e0b75d021b98078c4.tar.gz
bcm5719-llvm-acb6fa6bea2dfcbe5b4e327e0b75d021b98078c4.zip
Sema::FinalizeDeclaratorGroup(): Tighten up the tentative definition rule when dealing with arrays.
Bug submitted by Eli. llvm-svn: 46179
Diffstat (limited to 'clang')
-rw-r--r--clang/Sema/SemaDecl.cpp13
-rw-r--r--clang/test/Sema/array-constraint.c2
-rw-r--r--clang/test/Sema/incomplete-decl.c4
3 files changed, 14 insertions, 5 deletions
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index c2c66a20152..b1753e1df41 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -855,10 +855,15 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
// external linkage is valid (C99 6.2.2p5).
if (FVD && !FVD->getInit() && (FVD->getStorageClass() == VarDecl::Static ||
FVD->getStorageClass() == VarDecl::None)) {
- // C99 6.9.2p3: If the declaration of an identifier for an object is
- // a tentative definition and has internal linkage (C99 6.2.2p3), the
- // declared type shall not be an incomplete type.
- if (T->isIncompleteType()) {
+ const VariableArrayType *VAT = T->getAsVariableArrayType();
+
+ if (VAT && VAT->getSizeExpr() == 0) {
+ // C99 6.9.2 (p2, p5): Implicit initialization causes an incomplete
+ // array to be completed. Don't issue a diagnostic.
+ } else if (T->isIncompleteType()) {
+ // C99 6.9.2p3: If the declaration of an identifier for an object is
+ // a tentative definition and has internal linkage (C99 6.2.2p3), the
+ // declared type shall not be an incomplete type.
Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type,
T.getAsString());
IDecl->setInvalidDecl();
diff --git a/clang/test/Sema/array-constraint.c b/clang/test/Sema/array-constraint.c
index 8b2ce5eca4c..3ed5215accb 100644
--- a/clang/test/Sema/array-constraint.c
+++ b/clang/test/Sema/array-constraint.c
@@ -24,7 +24,7 @@ struct vari *func(struct vari a[]) { // expected-error {{'struct vari' may not b
return a;
}
-int foo[](void); // expected-error {{variable has incomplete type 'int (*[])(void)'}} expected-error {{'foo' declared as array of functions}}
+int foo[](void); // expected-error {{'foo' declared as array of functions}}
int foo2[1](void); // expected-error {{'foo2' declared as array of functions}}
typedef int (*pfunc)(void);
diff --git a/clang/test/Sema/incomplete-decl.c b/clang/test/Sema/incomplete-decl.c
index e342ab8b70c..047c24266e3 100644
--- a/clang/test/Sema/incomplete-decl.c
+++ b/clang/test/Sema/incomplete-decl.c
@@ -9,7 +9,11 @@ static struct foo g; // expected-error {{variable has incomplete type 'struct f
extern void d;
extern struct foo e;
+int ary[];
+struct foo bary[]; // expected-error {{array has incomplete element type 'struct foo'}}
+
void func() {
+ int ary[]; // expected-error{{variable has incomplete type 'int []'}}
void b; // expected-error {{variable has incomplete type 'void'}}
struct foo f; // expected-error {{variable has incomplete type 'struct foo'}}
}
OpenPOWER on IntegriCloud