[cfe-commits] r118428 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/compound-literal.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Nov 8 11:14:20 PST 2010


Author: akirtzidis
Date: Mon Nov  8 13:14:19 2010
New Revision: 118428

URL: http://llvm.org/viewvc/llvm-project?rev=118428&view=rev
Log:
When building a compound literal, check that the base element of the array is complete.
Fixes rdar://8620582 & http://llvm.org/PR7905

Added:
    cfe/trunk/test/SemaCXX/compound-literal.cpp
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=118428&r1=118427&r2=118428&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Nov  8 13:14:19 2010
@@ -3947,6 +3947,11 @@
   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()));

Added: cfe/trunk/test/SemaCXX/compound-literal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compound-literal.cpp?rev=118428&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/compound-literal.cpp (added)
+++ cfe/trunk/test/SemaCXX/compound-literal.cpp Mon Nov  8 13:14:19 2010
@@ -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}};
+}
+}





More information about the cfe-commits mailing list