]> granicus.if.org Git - clang/commitdiff
Instantiation of byref variable in
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 9 Jul 2010 21:27:28 +0000 (21:27 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 9 Jul 2010 21:27:28 +0000 (21:27 +0000)
block literal expression.

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

lib/Sema/TreeTransform.h
test/CodeGenCXX/instantiate-blocks.cpp
test/SemaCXX/instantiate-blocks.cpp [new file with mode: 0644]

index db5e2d10f44140f1d9bd0dcbd225795f41e05ffa..05ae38e84aa8e7911a26f85fe630b5fe9118768a 100644 (file)
@@ -6279,6 +6279,10 @@ TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
   if (!ND)
     return SemaRef.ExprError();
   
+  // Is this instantiation of a __block variable?
+  if (E->getDecl()->getAttr<BlocksAttr>())
+    ND->addAttr(::new (SemaRef.Context) BlocksAttr(BlocksAttr::ByRef));
+  
   if (!getDerived().AlwaysRebuild() &&
       ND == E->getDecl()) {
     // Mark it referenced in the new context regardless.
index 8c1c8dd234407173f28345ac6518df369f65ec43..7246f69e8ef42379e29d38c079508f794272d289 100644 (file)
@@ -18,7 +18,11 @@ int test1(void)
 template <typename T, typename T1> void foo(T t, T1 r)
 {
     T block_arg;
-    T1 (^block)(char, T, T1, double) =  ^ T1 (char ch, T arg, T1 arg2, double d1) { return block_arg+arg; };
+    __block T1 byref_block_arg;
+
+    T1 (^block)(char, T, T1, double) =  
+       ^ T1 (char ch, T arg, T1 arg2, double d1) { byref_block_arg = arg2;
+                                                   return byref_block_arg + arg; };
 
     void (^block2)() = ^{};
 }
diff --git a/test/SemaCXX/instantiate-blocks.cpp b/test/SemaCXX/instantiate-blocks.cpp
new file mode 100644 (file)
index 0000000..a4001a7
--- /dev/null
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
+// rdar: // 6182276
+
+template <typename T, typename T1> void foo(T t, T1 r)
+{
+    T block_arg;
+    __block T1 byref_block_arg;
+
+    T1 (^block)(T)  =  ^ T1 (T arg) { 
+         byref_block_arg = arg;
+         block_arg = arg;      // expected-error {{variable is not assignable (missing __block type specifier)}}
+         return block_arg+arg; };
+}
+
+int main(void)
+{
+    foo(100, 'a');     // expected-note {{in instantiation of function template specialization 'foo<int, char>' requested here}}
+}
+