aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-11-14 03:40:14 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-11-14 03:40:14 +0000
commit49e2b8e2e5d096851b5135ea5aed222e8aa95bde (patch)
tree94726830e0446a921e15f50cdb0b554c2562403d
parent19aeac6ea4897c542b21c9f53a0a51762d8ddf83 (diff)
Fix for PR5489: don't skip the complete type requrirement for variable
definitions just because the type happens to be an array type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88752 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDecl.cpp9
-rw-r--r--test/CodeGenCXX/init-incomplete-type.cpp12
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index fa31cc5ddb..65e839b04d 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3279,8 +3279,13 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) {
return;
}
- if (!VDecl->getType()->isArrayType() &&
- RequireCompleteType(VDecl->getLocation(), VDecl->getType(),
+ // A definition must end up with a complete type, which means it must be
+ // complete with the restriction that an array type might be completed by the
+ // initializer; note that later code assumes this restriction.
+ QualType BaseDeclType = VDecl->getType();
+ if (const ArrayType *Array = Context.getAsIncompleteArrayType(BaseDeclType))
+ BaseDeclType = Array->getElementType();
+ if (RequireCompleteType(VDecl->getLocation(), BaseDeclType,
diag::err_typecheck_decl_incomplete_type)) {
RealDecl->setInvalidDecl();
return;
diff --git a/test/CodeGenCXX/init-incomplete-type.cpp b/test/CodeGenCXX/init-incomplete-type.cpp
new file mode 100644
index 0000000000..402b86ea8c
--- /dev/null
+++ b/test/CodeGenCXX/init-incomplete-type.cpp
@@ -0,0 +1,12 @@
+// RUN: clang-cc %s -emit-llvm-only -verify
+// PR5489
+
+template<typename E>
+struct Bar {
+ int x_;
+};
+
+static struct Bar<int> bar[1] = {
+ { 0 }
+};
+