[cfe-commits] r72844 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/temp_class_spec.cpp
Douglas Gregor
dgregor at apple.com
Thu Jun 4 08:10:09 PDT 2009
On Jun 3, 2009, at 9:11 PM, Anders Carlsson wrote:
> Author: andersca
> Date: Wed Jun 3 23:11:30 2009
> New Revision: 72844
>
> URL: http://llvm.org/viewvc/llvm-project?rev=72844&view=rev
> Log:
> Template argument deduction for incomplete and constant array types.
> Doug, please review.
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=72844&r1=72843&r2=72844&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Jun 3 23:11:30
> 2009
> @@ -100,6 +100,35 @@
> Deduced);
> }
>
> + case Type::IncompleteArray: {
> + const IncompleteArrayType *IncompleteArrayArg =
> + Context.getAsIncompleteArrayType(Arg);
> + if (!IncompleteArrayArg)
> + return false;
> +
> + return DeduceTemplateArguments(Context,
> + Context.getAsIncompleteArrayType(Param)-
> >getElementType(),
> + IncompleteArrayArg-
> >getElementType(),
> + Deduced);
> + }
Looks good.
> + case Type::ConstantArray: {
> + const ConstantArrayType *ConstantArrayArg =
> + Context.getAsConstantArrayType(Arg);
> + if (!ConstantArrayArg)
> + return false;
> +
> + const ConstantArrayType *ConstantArrayParm =
> + Context.getAsConstantArrayType(Param);
> + if (ConstantArrayArg->getSize() != ConstantArrayParm-
> >getSize())
> + return false;
We can deduce the value of a non-type template parameter from an array
bound, so we'll need to call into a new version of
DeduceTemplateArguments here that can handle expressions. Example code:
template<typename T> struct is_array { static const bool value =
false; };
template<typename T, unsigned N> struct is_array<T[N]> { static
const bool value = true; };
is_array<int[12]>::value will be true, and we'll deduce T=int and N=12.
At the very least, please add a FIXME.
> + return DeduceTemplateArguments(Context,
> + ConstantArrayParm-
> >getElementType(),
> + ConstantArrayArg-
> >getElementType(),
> + Deduced);
> + }
> +
> default:
> break;
> }
Looks good!
- Doug
More information about the cfe-commits
mailing list