[英]Partially specializing on non-type template parameter of the wrong type
Consider the following: 考虑以下:
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 compiles the code, gcc does not. clang编译代码,gcc没有。
However, in the following highly related example: 但是,在以下高度相关的示例中:
template <unsigned >
struct uint_ { };
template <int I> // NB: int, not unsigned
void foo(uint_<I> ) { }
int main() {
foo(uint_<0>{} );
}
both compilers reject with no matching function call to foo
. 两个编译器拒绝没有匹配函数调用
foo
。 gcc's behavior is consistent, clang's is not - so one or the other compiler has a bug for one or both examples. gcc的行为是一致的,clang不是 - 所以一个或另一个编译器有一个或两个例子的错误。 Which compiler is correct?
哪个编译器正确?
GCC is correct. GCC是正确的。 [temp.deduct.type]/17 :
[temp.deduct.type] / 17 :
If
P
has a form that contains<i>
, and if the type of the corresponding value ofA
differs from the type ofi
, deduction fails.如果
P
具有包含<i>
的形式,并且如果A
的相应值的类型与i
的类型不同,则推断失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.