language-lawyer

Can class template constructors have a redundant template parameter list in c++20

雨燕双飞 提交于 2020-08-27 21:35:39
问题 As far as I'm aware, the following code: template<typename T> struct S { S<T>(); }; is well-formed, even though the <T> in the declaration of the constructor is redundant. However, on gcc trunk (but not on gcc10.2), with -std=c++20 this gives an error: error: expected unqualified-id before ')' token 3 | S<T>(); ^ The code compiles on clang trunk with -std=c++20 . Is this a bug, or is this a breaking change in c++20 that is yet to be implemented in all compilers? 回答1: There was a change, in

How does the template argument deduction perform for function template parameter when it is a class template with default argument

℡╲_俬逩灬. 提交于 2020-08-27 17:46:33
问题 template<typename T, typename U = T> struct Test{}; template<typename T> void func(Test<T>){ //#1 } int main(){ func(Test<int>{}); //#2 } Consider the above code, At the point of invocation of function template func , the type of argument is Test<int,int> , When call the function template, template argument deduction will perform. The rule of template argument deduction for function call is : temp.deduct#call-1 Template argument deduction is done by comparing each function template parameter