[cfe-commits] r73232 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/temp_class_spec_blocks.cpp

Douglas Gregor dgregor at apple.com
Fri Jun 12 15:37:33 PDT 2009


On Jun 12, 2009, at 9:23 AM, Anders Carlsson wrote:

> 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.

Cool. Comments below.

> 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);
> +    }
> +

Could you add a little "(Clang extension)" comment to call out the  
fact that blocks aren't standard C++?

> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- 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);
> }

We're missing some type-checking here to make sure that, e.g., the  
pointee type is actually a function type. I suggest pulling out the  
block-type checking from GetTypeForDeclarator into a separate routine  
(BuildBlockPointerType?) that does the type-checking and is used both  
by GetTypeForDeclarator and by InstantiateBlockPointerType.

	- Doug



More information about the cfe-commits mailing list