带数组的聚合模板的模板参数推导

考虑以下程序:

template<typename T>
struct A { T t[2]; };

int main()
{
   A a{1}; // only one value provided for 2-element array
   return a.t[0];
}

在 C++20 模式下,它在gcc.

<source>(6): error C2641: cannot deduce template arguments for 'A'
<source>(6): error C2780: 'A<T> A(void)': expects 0 arguments - 1 provided
<source>(2): note: see declaration of 'A'
<source>(6): error C2784: 'A<T> A(A<T>)': could not deduce template argument for 'A<T>' from 'int'
<source>(2): note: see declaration of 'A'
<source>(6): error C2784: 'A<T> A(A<T>)': could not deduce template argument for 'A<T>' from 'int'
<source>(2): note: see declaration of 'A'
<source>(6): error C2780: 'A<T> A(T,T)': expects 2 arguments - 1 provided
<source>(2): note: see declaration of 'A'

https://gcc.godbolt.org/z/6ejfW8G77

这两个编译器中的哪一个是正确的?

Clang这里是没有问题的,因为它还不支持带括号的聚合初始化)。

更新:微软承认了这个错误并承诺很快修复:https :
//developercommunity.visualstudio.com/t/template-argument-deduction-fails-in-case-of-aggre/1467260

以上是带数组的聚合模板的模板参数推导的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>