[英]Partially specializing on non-type template parameter of the wrong type
考虑以下:
template <unsigned >
struct uint_ { };
template <class >
struct X {
static constexpr bool value = false;
};
template <int I> // NB: int, not unsigned
struct X<uint_<I>> {
static constexpr bool value = true;
};
int main() {
static_assert(X<uint_<0>>::value, "!");
}
clang编译代码,gcc没有。
但是,在以下高度相关的示例中:
template <unsigned >
struct uint_ { };
template <int I> // NB: int, not unsigned
void foo(uint_<I> ) { }
int main() {
foo(uint_<0>{} );
}
两个编译器拒绝没有匹配函数调用foo
。 gcc的行为是一致的,clang不是 - 所以一个或另一个编译器有一个或两个例子的错误。 哪个编译器正确?
GCC是正确的。 [temp.deduct.type] / 17 :
如果
P
具有包含<i>
的形式,并且如果A
的相应值的类型与i
的类型不同,则推断失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.