【问题标题】:Template Argument Deduction Broken in Clang 6 for Temporary Objects临时对象的 Clang 6 中的模板参数推导被破坏
【发布时间】: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++


    【解决方案1】:

    这是 Clang 错误 34091

    幸运的是,它已经修复,并且 Clang compiles this without issue 的主干构建。

    然而,据我所知,目前没有办法在不更改代码的情况下解决此问题,除非在下一个 Clang 版本发布时升级到该版本。

    【讨论】:

      猜你喜欢
      • 2018-05-16
      • 2014-08-12
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-27
      • 2018-12-17
      相关资源
      最近更新 更多