[cfe-commits] r73232 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/temp_class_spec_blocks.cpp
Anders Carlsson
andersca at mac.com
Fri Jun 12 09:23:20 PDT 2009
Author: andersca
Date: Fri Jun 12 11:23:10 2009
New Revision: 73232
URL: http://llvm.org/viewvc/llvm-project?rev=73232&view=rev
Log:
Deducation and instantiation of block types.
Added:
cfe/trunk/test/SemaTemplate/temp_class_spec_blocks.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=73232&r1=73231&r2=73232&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Fri Jun 12 11:23:10 2009
@@ -433,6 +433,21 @@
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:
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=73232&r1=73231&r2=73232&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Fri Jun 12 11:23:10 2009
@@ -274,9 +274,13 @@
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
Added: cfe/trunk/test/SemaTemplate/temp_class_spec_blocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_class_spec_blocks.cpp?rev=73232&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_class_spec_blocks.cpp (added)
+++ cfe/trunk/test/SemaTemplate/temp_class_spec_blocks.cpp Fri Jun 12 11:23:10 2009
@@ -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];
More information about the cfe-commits
mailing list