[cfe-commits] r73070 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/temp_class_spec.cpp

Douglas Gregor dgregor at apple.com
Mon Jun 8 08:54:30 PDT 2009


On Jun 8, 2009, at 8:19 AM, Anders Carlsson wrote:

> Author: andersca
> Date: Mon Jun  8 10:19:08 2009
> New Revision: 73070
>
> URL: http://llvm.org/viewvc/llvm-project?rev=73070&view=rev
> Log:
> Template argument deduction for function types.

Cool.

> Modified:
>    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
>    cfe/trunk/test/SemaTemplate/temp_class_spec.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=73070&r1=73069&r2=73070&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Jun  8 10:19:08  
> 2009
> @@ -265,6 +265,37 @@
>       return false;
>     }
>
> +    case Type::FunctionProto: {
> +      const FunctionProtoType *FunctionProtoArg =
> +        dyn_cast<FunctionProtoType>(Arg);
> +      if (!FunctionProtoArg)
> +        return false;
> +
> +      const FunctionProtoType *FunctionProtoParam =
> +        cast<FunctionProtoType>(Param);
> +
> +      // Check return types.
> +      if (!DeduceTemplateArguments(Context,
> +                                   FunctionProtoParam- 
> >getResultType(),
> +                                   FunctionProtoArg->getResultType(),
> +                                   Deduced))
> +        return false;
> +
> +      if (FunctionProtoParam->getNumArgs() != FunctionProtoArg- 
> >getNumArgs())
> +        return false;

You'll also need to compare isVariadic() and getTypeQuals().


> +      for (unsigned I = 0, N = FunctionProtoParam->getNumArgs(); I ! 
> = N; ++I) {
> +        // Check argument types.
> +        if (!DeduceTemplateArguments(Context,
> +                                     FunctionProtoParam- 
> >getArgType(I),
> +                                     FunctionProtoArg->getArgType(I),
> +                                     Deduced))
> +          return false;
> +      }
> +
> +      return true;
> +    }
> +
>

Looks good!

	- Doug



More information about the cfe-commits mailing list