8
我想使用的std::initializer_list
一個別名,而不是自己這樣的:別名的std :: initializer_list在鐺
#include<initializer_list>
template< typename T >
using InitializerList = std::initializer_list<T>;
// note: candidate template ignored: couldn't infer template argument 'T'
template< typename T >
void f(InitializerList<T> list) {
}
int main() {
// error: no matching function for call to 'f'
f({1, 2, 3, 4, 5});
}
該代碼是好的使用gcc & CL。然而,使用鐺我得到一個錯誤:
<source>:11:3: error: no matching function for call to 'f'
f({1, 2, 3, 4, 5});
^
<source>:7:6: note: candidate template ignored: couldn't infer template argument 'T'
void f(InitializerList<T> list) {
^
1 error generated.
但是一個直接使用的std::initializer_list
沒有錯誤編譯。
#include<initializer_list>
template< typename T >
void f(std::initializer_list<T> list) {
}
int main() {
f({1, 2, 3, 4, 5});
}
我試過鐺的所有版本從3.4.2 到 4.0.0 和得到了相同的結果。鏘的行爲是否符合標準?
它編譯只是'GCC 6.3'(http://ideone.com/pQir1C)的罰款。這是叮咚imho中的一個錯誤。 – Jonas
這裏有一個[Clang bug](https://bugs.llvm.org//show_bug.cgi?id=23689)。 – TartanLlama