簡體   English   中英

部分專注於錯誤類型的非類型模板參數

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM