]> granicus.if.org Git - clang/commitdiff
PR13788: Don't perform checks on the initializer of a dependently-typed
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Nov 2012 23:03:14 +0000 (23:03 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 9 Nov 2012 23:03:14 +0000 (23:03 +0000)
variable. Previously we didn't notice the type was dependent if the only
dependence came from an array bound.

Patch by Brian Brooks!

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

lib/Sema/SemaDecl.cpp
test/SemaTemplate/dependent-sized_array.cpp

index 628d2245a87d8a6a3134e8b34dce38b088f60040..0092d5dab1f4f028435524f110be090c077931da 100644 (file)
@@ -7219,8 +7219,8 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
   // 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 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
 
     // 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 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
 
   Expr *Init = var->getInit();
   bool IsGlobal = var->hasGlobalStorage() && !var->isStaticLocal();
+  QualType baseType = Context.getBaseElementType(type);
 
   if (!var->getDeclContext()->isDependentContext() &&
       Init && !Init->isValueDependent()) {
index cf0e0f37ee047692419fa3e695d1caa5fbff0acd..6fdcaa63e5ad5ea3f2ddb68cd2628a1b2bfe42f2 100644 (file)
@@ -15,3 +15,14 @@ void f1() {
   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 }};
+  }
+}