简体   繁体   中英

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM