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.2到4.0.0的所有版本的clang 并得到了相同的结果.clang的行为是否符合标准?
| 归档时间: |
|
| 查看次数: |
158 次 |
| 最近记录: |