Index: test/SemaTemplate/dependent-sized_array.cpp
===================================================================
--- test/SemaTemplate/dependent-sized_array.cpp	(revision 167352)
+++ test/SemaTemplate/dependent-sized_array.cpp	(working copy)
@@ -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 }};
+  }
+}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp	(revision 167352)
+++ lib/Sema/SemaDecl.cpp	(working copy)
@@ -7170,8 +7170,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>()) {
@@ -7180,8 +7180,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);
@@ -7199,6 +7197,7 @@
 
   Expr *Init = var->getInit();
   bool IsGlobal = var->hasGlobalStorage() && !var->isStaticLocal();
+  QualType baseType = Context.getBaseElementType(type);
 
   if (!var->getDeclContext()->isDependentContext() &&
       Init && !Init->isValueDependent()) {
