2017-03-23 60 views
8

chcę użyć alias std::initializer_list zamiast sobie tak:Alias ​​std :: initializer_list w brzękiem

#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}); 
} 

Ten kod jest w porządku za pomocą GCC & cl. Jednak za pomocą szczęk pojawia się błąd:

<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. 

Ale bezpośrednie wykorzystanie std::initializer_list skompilować bez błędów.

#include<initializer_list> 

template< typename T > 
void f(std::initializer_list<T> list) { 
} 

int main() { 
    f({1, 2, 3, 4, 5}); 
} 

Próbowałem wszystkie wersje brzękiem od 3.4.2 do 4.0.0 i dostał ten sam rezultat. Czy zachowanie klangów jest standardowe?

+2

To kompiluje dobrze z 'gcc 6.3' (http://ideone.com/pQir1C). To jest błąd w clang imho. – Jonas

+6

Istnieje [błąd Clang] (https://bugs.llvm.org//show_bug.cgi?id=23689) na ten temat. – TartanLlama

Odpowiedz