[cfe-commits] r88752 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CodeGenCXX/init-incomplete-type.cpp

Eli Friedman eli.friedman at gmail.com
Fri Nov 13 19:40:14 PST 2009


Author: efriedma
Date: Fri Nov 13 21:40:14 2009
New Revision: 88752

URL: http://llvm.org/viewvc/llvm-project?rev=88752&view=rev
Log:
Fix for PR5489: don't skip the complete type requrirement for variable
definitions just because the type happens to be an array type.


Added:
    cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=88752&r1=88751&r2=88752&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Nov 13 21:40:14 2009
@@ -3279,8 +3279,13 @@
     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;

Added: cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp?rev=88752&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/init-incomplete-type.cpp Fri Nov 13 21:40:14 2009
@@ -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 }
+};
+





More information about the cfe-commits mailing list