]> granicus.if.org Git - clang/commitdiff
When building a compound literal, check that the base element of the array is complete.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 8 Nov 2010 19:14:19 +0000 (19:14 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 8 Nov 2010 19:14:19 +0000 (19:14 +0000)
Fixes rdar://8620582 & http://llvm.org/PR7905

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118428 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/compound-literal.cpp [new file with mode: 0644]

index 38e45c8a5f1961f72f80aca1b1b725e8fbbc118d..0d0f48cd743e60f07485347489bf760a01fe6c29 100644 (file)
@@ -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 (file)
index 0000000..fe0e45d
--- /dev/null
@@ -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 <typename T> struct M { T m; };
+void foo2() {
+  (void)(M<short> []) {{3}};
+}
+}