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?

有帮助吗?

解决方案

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

其他提示

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>>{};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top