]> granicus.if.org Git - clang/commitdiff
Fix for PR5489: don't skip the complete type requrirement for variable
authorEli Friedman <eli.friedman@gmail.com>
Sat, 14 Nov 2009 03:40:14 +0000 (03:40 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sat, 14 Nov 2009 03:40:14 +0000 (03:40 +0000)
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

lib/Sema/SemaDecl.cpp
test/CodeGenCXX/init-incomplete-type.cpp [new file with mode: 0644]

index fa31cc5ddb0b7adc9710e07c63d8fee29916f5d3..65e839b04db93699490b8eebdac52cf9e2d95c61 100644 (file)
@@ -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 (file)
index 0000000..402b86e
--- /dev/null
@@ -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 }
+};
+