Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias std::initializer_list in clang

I want to use an alias of std::initializer_list instead of itself like that:

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

That code is fine using gcc & cl. However, using clang I get an error:

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

But an direct use of std::initializer_list compile with no error.

#include<initializer_list>

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

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

I tried all versions of clang from 3.4.2 to 4.0.0 and got same result. Does clang's behavior meet standard?

like image 802
Bromine Wang Avatar asked Mar 23 '17 07:03

Bromine Wang


1 Answers

Answer: this is a known bug in LLVM as described by Jonas in the comments.

https://bugs.llvm.org//show_bug.cgi?id=23689

like image 59
jaybny Avatar answered Oct 23 '22 19:10

jaybny