2017-03-23 42 views
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 得到了相同的結果。鏘的行爲是否符合標準?

+2

它編譯只是'GCC 6.3'(http://ideone.com/pQir1C)的罰款。這是叮咚imho中的一個錯誤。 – Jonas

+6

這裏有一個[Clang bug](https://bugs.llvm.org//show_bug.cgi?id=23689)。 – TartanLlama

回答

相關問題