【发布时间】:2018-05-21 01:15:11
【问题描述】:
对于临时对象,Clang 6 中的模板参数推导似乎被破坏了。
g++ 8.1.0 可以正确编译和运行示例。
Clang 6.0.0 和 6.0.2 都在指示行出错,并显示以下消息:
error: expected unqualified-id
Print{1,"foo"s,2}; /********** Broken in Clang **********/
所有其他行都正常工作。
无论是使用-std=c++17 还是-std=c++2a,这两种情况下的行为都是相同的。
The Clang c++ Status Page 表示模板参数推导是从 Clang 5 (P0091R3, P0512R0) 开始实现的。
这是一个错误吗?是否有解决方法(例如编译器标志,不是代码更改)?
示例:
template<class ...Ts>
void print(Ts...ts){ (( cout << ... << ts )); }
template<class ...Ts>
struct Print {
Print(Ts...ts){ (( cout << ... << ts )); }
};
int main(){
Print{1,"foo"s,2}; /********** Broken in Clang **********/
Print<int,string,int>{1,"foo"s,2};
auto p1 = Print{1,"foo"s,2};
Print p2{1,"foo"s,2};
print(1,"foo"s,2);
}
【问题讨论】:
标签: c++ templates clang c++17 clang++