[cfe-commits] r167642 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaTemplate/dependent-sized_array.cpp

Richard Smith richard-llvm at metafoo.co.uk
Fri Nov 9 15:03:14 PST 2012


Author: rsmith
Date: Fri Nov  9 17:03:14 2012
New Revision: 167642

URL: http://llvm.org/viewvc/llvm-project?rev=167642&view=rev
Log:
PR13788: Don't perform checks on the initializer of a dependently-typed
variable. Previously we didn't notice the type was dependent if the only
dependence came from an array bound.

Patch by Brian Brooks!

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaTemplate/dependent-sized_array.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=167642&r1=167641&r2=167642&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Nov  9 17:03:14 2012
@@ -7219,8 +7219,8 @@
   // All the following checks are C++ only.
   if (!getLangOpts().CPlusPlus) return;
 
-  QualType baseType = Context.getBaseElementType(var->getType());
-  if (baseType->isDependentType()) return;
+  QualType type = var->getType();
+  if (type->isDependentType()) return;
 
   // __block variables might require us to capture a copy-initializer.
   if (var->hasAttr<BlocksAttr>()) {
@@ -7229,8 +7229,6 @@
 
     // Regardless, we don't want to ignore array nesting when
     // constructing this copy.
-    QualType type = var->getType();
-
     if (type->isStructureOrClassType()) {
       SourceLocation poi = var->getLocation();
       Expr *varRef =new (Context) DeclRefExpr(var, false, type, VK_LValue, poi);
@@ -7248,6 +7246,7 @@
 
   Expr *Init = var->getInit();
   bool IsGlobal = var->hasGlobalStorage() && !var->isStaticLocal();
+  QualType baseType = Context.getBaseElementType(type);
 
   if (!var->getDeclContext()->isDependentContext() &&
       Init && !Init->isValueDependent()) {

Modified: cfe/trunk/test/SemaTemplate/dependent-sized_array.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-sized_array.cpp?rev=167642&r1=167641&r2=167642&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/dependent-sized_array.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-sized_array.cpp Fri Nov  9 17:03:14 2012
@@ -15,3 +15,14 @@
   int a1[] = { 1, 2, 3, N };
   int a3[sizeof(a1)/sizeof(int) != 4? 1 : -1]; // expected-error{{negative}}
 }
+
+namespace PR13788 {
+  template <unsigned __N>
+  struct S {
+    int V;
+  };
+  template <int N>
+  void foo() {
+    S<0> arr[N] = {{ 4 }};
+  }
+}





More information about the cfe-commits mailing list