So in your case, you want to have a reference type deduced (by template argument deduction),

but currently [expr.type]/1 disagrees (https://timsong-cpp.github.io/cppwp/expr.type#1): If an expression initially has the type “reference to T” ([dcl.ref], [dcl.init.ref]), the type is adjusted to T prior to any further analysis.
 

 

The copy constructor is something special (compared to other constructors).

 

Why do you want to handle it by a template

 
template <typename T> base(T x) {}
 
 
and not even

 

 
template <typename T> base(T& x) {}

 

 

in the first place?

 

 

-----Ursprüngliche Nachricht-----
Von: David wang via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Di 07.05.2024 09:46
Betreff: [std-proposals] Pass derived object by reference to single parameter delegated templated constructors
An: C++ <std-proposals@lists.isocpp.org>;
CC: David wang <wangjufan@gmail.com>;
On Mon, 6 May 2024 10:18:35 -0400  Jason McKesson via Std-Proposals
<std-proposals@lists.isocpp.org> wrote:
>This is way too special-case to implement. It's ultimately on the user
>to prevent this from happening. `base`'s constructor uses template
>argument deduction. That function takes its parameter by value. If you
>use template argument deduction on such a function and pass it a type
>which is a reference, it will copy the parameter. This *needs* to be a
>hard-and-fast rule.
 
It is a special case. It is a conflict between rule and best practices.
But It is not the user's fault. Rules and practices may change or be refined by us.

 

-- 
 Std-Proposals mailing list
 Std-Proposals@lists.isocpp.org
 https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals