[cfe-commits] r84347 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p4.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sat Oct 17 12:37:06 PDT 2009


Author: cornedbee
Date: Sat Oct 17 14:37:06 2009
New Revision: 84347

URL: http://llvm.org/viewvc/llvm-project?rev=84347&view=rev
Log:
In some dependent contexts, incomplete array types persist into FinalizeDeclaratorGroup. Don't require them to have a complete type. This allows us to compile Hello World with the Apache stdcxx library. If you don't use endl, it even links and runs.

Added:
    cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p4.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=84347&r1=84346&r2=84347&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Oct 17 14:37:06 2009
@@ -3527,10 +3527,37 @@
     // Block scope. C99 6.7p7: If an identifier for an object is declared with
     // no linkage (C99 6.2.2p6), the type for the object shall be complete...
     if (IDecl->isBlockVarDecl() && !IDecl->hasExternalStorage()) {
-      if (!IDecl->isInvalidDecl() &&
-          RequireCompleteType(IDecl->getLocation(), T,
-                              diag::err_typecheck_decl_incomplete_type))
-        IDecl->setInvalidDecl();
+      if (T->isDependentType()) {
+        // If T is dependent, we should not require a complete type.
+        // (RequireCompleteType shouldn't be called with dependent types.)
+        // But we still can at least check if we've got an array of unspecified
+        // size without an initializer.
+        if (!IDecl->isInvalidDecl() && T->isIncompleteArrayType() &&
+            !IDecl->getInit()) {
+          Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
+            << T;
+          IDecl->setInvalidDecl();
+        }
+      } else if (!IDecl->isInvalidDecl()) {
+        // If T is an incomplete array type with an initializer list that is
+        // dependent on something, its size has not been fixed. We could attempt
+        // to fix the size for such arrays, but we would still have to check
+        // here for initializers containing a C++0x vararg expansion, e.g.
+        // template <typename... Args> void f(Args... args) {
+        //   int vals[] = { args };
+        // }
+        const IncompleteArrayType *IAT = T->getAs<IncompleteArrayType>();
+        Expr *Init = IDecl->getInit();
+        if (IAT && Init &&
+            (Init->isTypeDependent() || Init->isValueDependent())) {
+          // Check that the member type of the array is complete, at least.
+          if (RequireCompleteType(IDecl->getLocation(), IAT->getElementType(),
+                                  diag::err_typecheck_decl_incomplete_type))
+            IDecl->setInvalidDecl();
+        } else if (RequireCompleteType(IDecl->getLocation(), T,
+                                      diag::err_typecheck_decl_incomplete_type))
+          IDecl->setInvalidDecl();
+      }
     }
     // File scope. C99 6.9.2p2: A declaration of an identifier for an
     // object that has file scope without an initializer, and without a

Added: cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p4.cpp?rev=84347&view=auto

==============================================================================
--- cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p4.cpp (added)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p4.cpp Sat Oct 17 14:37:06 2009
@@ -0,0 +1,18 @@
+// RUN: clang-cc -fsyntax-only -verify -std=c++98 -pedantic -Werror  %s
+int a1[] = { 1, 3, 5 };
+void f() {
+  int a2[] = { 1, 3, 5 };
+}
+template <typename T>
+void tf() {
+  T t;
+  // Element type may be dependent
+  T a3[] = { 1, 3, 5 };
+  // As might be the initializer list, value
+  int a5[] = { sizeof(T) };
+  // or even type.
+  int a6[] = { t.get() };
+}
+
+// Allowed by GNU extension
+int a4[] = {}; // expected-warning {{zero size arrays}}





More information about the cfe-commits mailing list