![](/img/trans.png)
[英]Clang vs GCC - Variadic template parameter pack followed by parameter with default value works in GCC 4.8 but not Clang 3.5
[英]clang vs gcc - CTAD of struct deriving from template parameter
考虑以下代码:
template <typename B>
struct D : B { };
D d{[]{ }};
gcc 12.x 接受它并按预期推断d
是D</* type of lambda */>
。
clang 14.x 拒绝它并出现以下错误:
<source>:4:3: error: no viable constructor
or deduction guide for deduction of template arguments of 'D'
D d{[]{ }};
^
<source>:2:8: note: candidate template ignored:
could not match 'D<B>' against '(lambda at <source>:4:5)'
struct D : B { };
^
<source>:2:8: note: candidate function template not viable:
requires 0 arguments, but 1 was provided
哪个编译器在这里表现正确?
在代码片段中,没有提供任何扣除指南。 P1816为 C++20 中的聚合 class 模板添加了推导指南,要求生成聚合推导候选。
代码有效,但 Clang还不支持 P1816 。
添加推导指南也可以在 Clang 中编译。
template <typename B> D(B) -> D<B>;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.