[PATCH] Canonicalize the variadic template alias with multiple ellipsis.

Logan Chien tzuhsiang.chien at gmail.com
Tue Jul 8 17:06:39 PDT 2014


Ping.


On Mon, Jul 7, 2014 at 9:01 PM, Logan Chien <tzuhsiang.chien at gmail.com>
wrote:

> Ping?
>
> This patch tries to fix an assertion failure related to the template alias
> with two (or more) parameter packs.  For example,
>
>
> template <typename... T> struct tuple;
> template <typename... T> struct extract_;
> template <typename... T> using extract = typename extract_<T...>::type;
>
> template <typename... A, typename... B>
> inline auto test(tuple<A...>&& xs, B&&... ys) -> extract<A&&..., B...> { }
>
> Please have a look, and feel free to let me know if there is any problem.
> Thanks!
>
> Sincerely,
> Logan
>
>
> On Mon, Jun 30, 2014 at 1:10 AM, Logan Chien <tzuhsiang.chien at gmail.com>
> wrote:
>
>> Hi rsmith,
>>
>> If the template has two variadic formal parameters, then the type
>> might not be canonical.  We have call ASTContext.getCanonicalType()
>> to canonicalize the type; otherwise, an assertion failure will be
>> raised.
>>
>> This patch fix this issue by adding getCanonicalType() in
>> TransformTemplateTypeParmType.
>>
>> http://reviews.llvm.org/D4343
>>
>> Files:
>>   lib/Sema/SemaTemplateInstantiate.cpp
>>   test/SemaTemplate/alias-templates.cpp
>>
>> Index: lib/Sema/SemaTemplateInstantiate.cpp
>> ===================================================================
>> --- lib/Sema/SemaTemplateInstantiate.cpp
>> +++ lib/Sema/SemaTemplateInstantiate.cpp
>> @@ -1376,7 +1376,7 @@
>>      assert(Arg.getKind() == TemplateArgument::Type &&
>>             "Template argument kind mismatch");
>>
>> -    QualType Replacement = Arg.getAsType();
>> +    QualType Replacement =
>> getSema().Context.getCanonicalType(Arg.getAsType());
>>
>>      // TODO: only do this uniquing once, at the start of instantiation.
>>      QualType Result
>> Index: test/SemaTemplate/alias-templates.cpp
>> ===================================================================
>> --- test/SemaTemplate/alias-templates.cpp
>> +++ test/SemaTemplate/alias-templates.cpp
>> @@ -201,3 +201,17 @@
>>    template <typename T, typename U, typename V>
>>    using derived2 = ::PR16904::base<T, U>::template derived<V>; //
>> expected-error {{expected a type}} expected-error {{expected ';'}}
>>  }
>> +
>> +namespace VariadicTemplateAlias {
>> +  template <typename... T> struct tuple;
>> +  template <typename... T> struct extract_;
>> +
>> +  // Note: Both the template alias and the concatenation of variadic
>> template
>> +  // arguments A and B are required to trigger the assertion failure.
>> +
>> +  template <typename... T>
>> +  using extract = typename extract_<T...>::type;
>> +
>> +  template <typename... A, typename... B>
>> +  inline auto test(tuple<A...>&& xs, B&&... ys) -> extract<A&&..., B...>
>> { }
>> +}
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140709/b075a823/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Canonicalize-the-variadic-template-alias-with-multip.patch
Type: text/x-patch
Size: 1956 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140709/b075a823/attachment.bin>


More information about the cfe-commits mailing list