看看this code:
template<class T>
struct S {
template<class U>
S(U) {}
};
template<typename T>
using SP = S<T*>;
// template<class U>
// S(U) -> S<U*>;
template<class U>
S(U) -> SP<U>;
S s(0);
[不幸的是,它被Clang拒绝:
error: deduced type 'SP<U>' (aka 'S<type-parameter-0-0 *>') of deduction guide is not written as a specialization of template 'S' S(U) -> SP<U>; ^~~~~~~~~~
ICC拒绝它,或者出现类似错误:
error: the return type must directly designate a specialization of the associated class template
但是,GCC和MSVC都编译此代码。
哪个编译器正确?毕竟,类型别名只是别名。
Clang和ICC在这里是正确的:模板和类型的命名方式限制为phrased syntactically。 C ++ 20允许别名模板的“类模板”参数推导,但不支持(单独)它们的推导指南。