This is because C++17 allowed a template type argument to be deduced from the type of a non-type argument. [temp.deduct.type]/13:当参数的值对应于非类型模板时用从属类型声明的参数 P 从一个表达式,推导出 P 类型的模板参数值的类型.When the value of the argument corresponding to a non-type templateparameter P that is declared with a dependent type is deduced froman expression, the template parameters in the type of P are deducedfrom the type of the value.因此,当我们尝试将 S< int const,nullptr> 与部分专业化进行匹配时,我们从两个来源推论出部分专业化的模板参数 T :So when we try to match S<int const, nullptr> against the partial specialization, we deduce the partial specialization's template parameter T from two sources:从第一个模板参数 int const 推断出 T = int const 从第二个模板参数(其类型为 void(*)(int),因为函数参数的顶级cv限定已被调整)中,我们推导出 T = int .From the first template argument int const, we deduce T = int constFrom the second template argument (which has type void (*)(int) because the top-level cv-qualification of function parameters are adjusted away), we deduce T = int.由于我们推导了矛盾的结果,推论失败了,并且部分专业化不是匹配项.Since we deduced conflicting results, the deduction fails and the partial specialization is not a match.在2019年,在核心反射器上提出了类似的例子.人们一致认为这是标准中的缺陷,并且从非类型模板参数的类型中推论应该仅适用于那些不符合条件的情况.否则可以推论.Similar examples were brought up on the core reflector back in 2019. There was some agreement that this was a defect in the standard, and that deduction from the type of a non-type template argument should only happen for things that are not otherwise deducible. 这篇关于为什么Clang比C ++ 17的专业化更偏爱主模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-06 10:00