当模板参数全部被推导时,它们的顺序是否重要?

Ben*_*Ben 12 c++ language-lawyer template-argument-deduction

我发现 Clang、GCC 和 MSVC 之间存在差异,其中 GCC 和 Clang 执行了我所期望的操作:

#include <Eigen/Core>

template <typename Indices, typename T, int Rows> //< Bad
//template <typename Indices, int Rows, typename T> //< OK
//template <typename T, int Rows, typename Indices> //< OK
//template <typename T, typename Indices, int Rows> //< Bad
//template <int Rows, typename Indices, typename T> //< Bad
//template <int Rows, typename T, typename Indices> //< Bad
void f(
    const Eigen::Matrix<T, Rows, 1>&,
    const Indices&
) {}


int main() {
    f(Eigen::Matrix<double, 6, 1>{}, 1);
}
Run Code Online (Sandbox Code Playgroud)

MSVC不会编译它,但GCCClang会编译。

这是 MSVC 错误吗?MSVC 说:

<source>(16): error C2672: 'f': no matching overloaded function found
<source>(9): note: could be 'void f(const Eigen::Matrix<T,Rows,1,0|_Rows==1&&false?Eigen::RowMajor:true&&_Rows!=1?Eigen::ColMajor:Eigen::ColMajor,_Rows,1> &,const Indices &)'
<source>(16): note: 'void f(const Eigen::Matrix<T,Rows,1,0|_Rows==1&&false?Eigen::RowMajor:true&&_Rows!=1?Eigen::ColMajor:Eigen::ColMajor,_Rows,1> &,const Indices &)': could not deduce template argument for 'const Eigen::Matrix<T,Rows,1,0|_Rows==1&&false?Eigen::RowMajor:true&&_Rows!=1?Eigen::ColMajor:Eigen::ColMajor,_Rows,1> &' from 'Eigen::Matrix<double,6,1,0,6,1>'
Compiler returned: 2
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试其他顺序的模板参数(如“OK”和“Bad”注释所示),它会接受一些订单。

Ben*_*uch 6

这是 MSVC 中的一个错误。我已向Microsoft提交了错误报告。

它已作为重复项关闭,预计将在 VS 2022 v17.7 (MSVC 19.36) 中修复。

感谢Ben的发现,感谢Ted Lyngmo273K在评论中对其进行分析!