]> granicus.if.org Git - clang/commitdiff
Deducation and instantiation of block types.
authorAnders Carlsson <andersca@mac.com>
Fri, 12 Jun 2009 16:23:10 +0000 (16:23 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 12 Jun 2009 16:23:10 +0000 (16:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73232 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateDeduction.cpp
lib/Sema/SemaTemplateInstantiate.cpp
test/SemaTemplate/temp_class_spec_blocks.cpp [new file with mode: 0644]

index fe64946e14db1ba4a868990a0887371c22bd43a8..0bef27c7261d8ee531de2c1b2957537d7a25752c 100644 (file)
@@ -433,6 +433,21 @@ static bool DeduceTemplateArguments(ASTContext &Context, QualType Param,
                                 Deduced);
     }
 
+    //     type(^)(T) 
+    //     T(^)() 
+    //     T(^)(T) 
+    case Type::BlockPointer: {
+      const BlockPointerType *BlockPtrParam = cast<BlockPointerType>(Param);
+      const BlockPointerType *BlockPtrArg = dyn_cast<BlockPointerType>(Arg);
+      
+      if (!BlockPtrArg)
+        return false;
+      
+      return DeduceTemplateArguments(Context,
+                                     BlockPtrParam->getPointeeType(),
+                                     BlockPtrArg->getPointeeType(), Deduced);
+    }
+
     case Type::TypeOfExpr:
     case Type::TypeOf:
     case Type::Typename:
index 964d3b14853f8e45fad0e9617c41ff49e5377eab..a7fdb59a2047c7b584a4784466ffb46c93ae6bdd 100644 (file)
@@ -274,9 +274,13 @@ TemplateTypeInstantiator::InstantiatePointerType(const PointerType *T,
 QualType 
 TemplateTypeInstantiator::InstantiateBlockPointerType(const BlockPointerType *T,
                                                       unsigned Quals) const {
-  // FIXME: Implement this
-  assert(false && "Cannot instantiate BlockPointerType yet");
-  return QualType();
+  QualType PointeeType = Instantiate(T->getPointeeType());
+  if (PointeeType.isNull())
+    return QualType();
+  
+  QualType BlockTy = SemaRef.Context.getBlockPointerType(PointeeType);
+  
+  return BlockTy.getQualifiedType(Quals);
 }
 
 QualType
diff --git a/test/SemaTemplate/temp_class_spec_blocks.cpp b/test/SemaTemplate/temp_class_spec_blocks.cpp
new file mode 100644 (file)
index 0000000..920d9c8
--- /dev/null
@@ -0,0 +1,34 @@
+// RUN: clang-cc -fsyntax-only -verify %s -fblocks
+template<typename T>
+struct is_unary_block {
+  static const bool value = false;
+};
+
+template<typename T, typename U>
+struct is_unary_block<T (^)(U)> {
+  static const bool value = true;
+};
+
+int is_unary_block0[is_unary_block<int>::value ? -1 : 1];
+int is_unary_block1[is_unary_block<int (^)()>::value ? -1 : 1];
+int is_unary_block2[is_unary_block<int (^)(int, bool)>::value ? -1 : 1];
+int is_unary_block3[is_unary_block<int (^)(bool)>::value ? 1 : -1];
+int is_unary_block4[is_unary_block<int (^)(int)>::value ? 1 : -1];
+
+template<typename T>
+struct is_unary_block_with_same_return_type_as_argument_type {
+  static const bool value = false;
+};
+
+template<typename T>
+struct is_unary_block_with_same_return_type_as_argument_type<T (^)(T)> {
+  static const bool value = true;
+};
+
+int is_unary_block5[is_unary_block_with_same_return_type_as_argument_type<int>::value ? -1 : 1];
+int is_unary_block6[is_unary_block_with_same_return_type_as_argument_type<int (^)()>::value ? -1 : 1];
+int is_unary_block7[is_unary_block_with_same_return_type_as_argument_type<int (^)(int, bool)>::value ? -1 : 1];
+int is_unary_block8[is_unary_block_with_same_return_type_as_argument_type<int (^)(bool)>::value ? -1 : 1];
+int is_unary_block9[is_unary_block_with_same_return_type_as_argument_type<int (^)(int)>::value ? 1 : -1];
+int is_unary_block10[is_unary_block_with_same_return_type_as_argument_type<int (^)(int, ...)>::value ? -1 : 1];
+int is_unary_block11[is_unary_block_with_same_return_type_as_argument_type<int (^ const)(int)>::value ? -1 : 1];