Title
[tiny] Templated constructor accidentally preferred over copy constructor
Status
nad
Section
[over]
Submitter
Nevin Liber

Created on 2012-10-19.00:00:00 last changed 136 months ago

Messages

Date: 2013-10-11.23:34:25


struct Silly
{
    template<class... Ts>
    Silly(Ts&&...)
    {}
};

int main()
{
    Silly s;
    Silly t(s);	// Silly::Silly(Ts &&...) [Ts = <Silly &>]
    const Silly u;
    Silly v(u); // calls Silly::Silly(Silly const&)
}
The problem is that users expect the copy constructor to be called in both situations. Note: you do not need variadics for this; it made the example smaller. Also, this issue existed in C++03, but rarely happened in practice because templated parameters were usually declared const T&.

Bristol 2013: Sutton and Gregor proposed various work-arounds, like additional overloads and constraints. Stroustrup asked whether having a copying template have different semantics from a copy constructor isn't an error, and Gregor explained that tuples run into that issue and they have different semantics for the template. The submitter is encouraged to write a paper, and practical examples are desirable.

The EWG decided to close this issue as a NAD in Chicago 2013.

History
Date User Action Args
2013-10-11 23:34:25adminsetstatus: open -> nad
2012-10-19 00:00:00admincreate