在clang中别名std :: initializer_list

Bro*_*ang 8 c++ clang c++11 clang++

我想使用别名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});
}
Run Code Online (Sandbox Code Playgroud)

使用gcc&cl,该代码很好.但是,使用clang我收到错误:

<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.
Run Code Online (Sandbox Code Playgroud)

但直接使用std::initializer_list编译没有错误.

#include<initializer_list>

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

int main() {
  f({1, 2, 3, 4, 5});
}
Run Code Online (Sandbox Code Playgroud)

我尝试了从3.4.24.0.0的所有版本的clang 并得到了相同的结果.clang的行为是否符合标准?

jay*_*bny 1

答案:这是 LLVM 中的一个已知错误,如 Jonas 在评论中所述。

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