[英]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.