相关疑难解决方法(0)

模板参数扣除在Clang 6中为临时物体打破

对于临时对象,在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 **********/
Run Code Online (Sandbox Code Playgroud)

所有其他行正常工作.

该行为是在两种情况下是否相同-std=c++17-std=c++2a使用.

Clang c ++状态页面表示模板参数推断是从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);
}
Run Code Online (Sandbox Code Playgroud)

c++ templates clang clang++ c++17

7
推荐指数
1
解决办法
155
查看次数

标签 统计

c++ ×1

c++17 ×1

clang ×1

clang++ ×1

templates ×1