diff options
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 9 | ||||
-rw-r--r-- | test/CodeGenCXX/init-incomplete-type.cpp | 12 |
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 } +}; + |