From: Argyrios Kyrtzidis Date: Mon, 8 Nov 2010 19:14:19 +0000 (+0000) Subject: When building a compound literal, check that the base element of the array is complete. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6fe9a28bc5ceec284099c1e5bc90e2316ade3de;p=clang When building a compound literal, check that the base element of the array is complete. Fixes rdar://8620582 & http://llvm.org/PR7905 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118428 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 38e45c8a5f..0d0f48cd74 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3947,6 +3947,11 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, QualType literalType = TInfo->getType(); if (literalType->isArrayType()) { + if (RequireCompleteType(LParenLoc, Context.getBaseElementType(literalType), + PDiag(diag::err_illegal_decl_array_incomplete_type) + << SourceRange(LParenLoc, + literalExpr->getSourceRange().getEnd()))) + return ExprError(); if (literalType->isVariableArrayType()) return ExprError(Diag(LParenLoc, diag::err_variable_object_no_init) << SourceRange(LParenLoc, literalExpr->getSourceRange().getEnd())); diff --git a/test/SemaCXX/compound-literal.cpp b/test/SemaCXX/compound-literal.cpp new file mode 100644 index 0000000000..fe0e45d3c6 --- /dev/null +++ b/test/SemaCXX/compound-literal.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// http://llvm.org/PR7905 +namespace PR7905 { +struct S; // expected-note {{forward declaration}} +void foo1() { + (void)(S[]) {{3}}; // expected-error {{array has incomplete element type}} +} + +template struct M { T m; }; +void foo2() { + (void)(M []) {{3}}; +} +}