]> granicus.if.org Git - clang/commitdiff
Fix an error with the declaration of block parameters that depend
authorJohn McCall <rjmccall@apple.com>
Tue, 22 Mar 2011 23:15:50 +0000 (23:15 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 22 Mar 2011 23:15:50 +0000 (23:15 +0000)
on previous block parameters that crept in as part of my captures
work a month or so ago.

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

lib/Sema/SemaExpr.cpp
test/Sema/block-args.c

index a27864f673dbdf31c6552b8271da278a71899671..b8f0c729d1788ba0652738d8c709b2f5f56281e8 100644 (file)
@@ -782,11 +782,20 @@ diagnoseUncapturableValueReference(Sema &S, SourceLocation loc,
   // diagnose this.
   if (!S.CurContext->isFunctionOrMethod()) return CR_NoCapture;
 
-  // This particular madness can happen in ill-formed default
-  // arguments; claim it's okay and let downstream code handle it.
-  if (isa<ParmVarDecl>(var) &&
-      S.CurContext == var->getDeclContext()->getParent())
-    return CR_NoCapture;
+  // Certain madnesses can happen with parameter declarations, which
+  // we want to ignore.
+  if (isa<ParmVarDecl>(var)) {
+    // - If the parameter still belongs to the translation unit, then
+    //   we're actually just using one parameter in the declaration of
+    //   the next.  This is useful in e.g. VLAs.
+    if (isa<TranslationUnitDecl>(var->getDeclContext()))
+      return CR_NoCapture;
+
+    // - This particular madness can happen in ill-formed default
+    //   arguments; claim it's okay and let downstream code handle it.
+    if (S.CurContext == var->getDeclContext()->getParent())
+      return CR_NoCapture;
+  }
 
   DeclarationName functionName;
   if (FunctionDecl *fn = dyn_cast<FunctionDecl>(var->getDeclContext()))
index e2e2d8e44622eea5a1984c05ba1e83a501474eba..5ee383eebb0241920bfd91e621bfa8d6b86079d0 100644 (file)
@@ -40,3 +40,8 @@ void test4() {
   int (^f)() = ^((x)) { }; // expected-error {{expected ')'}} expected-warning {{type specifier missing}} expected-note {{to match this}}
 }
 
+// rdar://problem/9170609
+void test5_helper(void (^)(int, int[*]));
+void test5(void) {
+  test5_helper(^(int n, int array[n]) {});
+}