4

Given a template alias

template<unsigned U>
using uint_ = integral_constant<unsigned,U>;

The partial specialization of

template<class T,class P>
struct size{};

as

template <class T,unsigned U>
struct size<T,uint_<U>>{};

generates a warning astemplate parameter can not be deduced for clang 3.1 while no warning is generated with gcc 4.7

So, is it malformed code?

abir
  • 1,797
  • 14
  • 26
  • 3
    I see no reason why that should not work. Alias templates are substituted immediately. – Johannes Schaub - litb Aug 28 '12 at 10:59
  • Not only it gives warning in clang 3.1 but it ignores the specialization if I try to instantiate it. However using integral_constant directly in place of alias works as usual. I guess it is clang bug. – abir Aug 28 '12 at 11:15
  • @abir: That means template alias isn't implemented correctly in Clang. – Nawaz Aug 28 '12 at 12:02

2 Answers2

5

The code is perfectly fine in C++11. The Clang's warning can be ignored.

Nawaz
  • 353,942
  • 115
  • 666
  • 851
3

Another guy said that this is a Clang bug. You can work it around if you change the using declaration like this

template<unsigned T, unsigned U = T>
using uint_ = integral_constant<unsigned,U>;

As an educated guess, apparently Clang does not correctly update the identity of the template parameter that appears in the type-id. So it thinks in your example that the resulting type uint_<U> refers to the first parameter of the partial specialization (because within uint_ that is the case, but not in the point of use). Alternatively you can exchange the order at the point of use

template <unsigned U,class T>
struct size<T,uint_<U>>{};
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212