This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


1959. Inadvertently inherited copy constructor

Section: _N4527_.12.9  [class.inhctor]     Status: CD4     Submitter: David Krauss     Date: 2014-06-30

[Adopted at the October, 2015 meeting as P0136R1.]

Consider the following example:

  struct a {
    a() = default;
    a( a const & ) { std::cout << "copy\n"; }
    template< typename t >
    a( t ) { std::cout << "convert\n"; }
  };

  struct b : a {
    using a::a;
  };

  a x;
  b y = x;

The copy constructor is invoked by the inherited constructor template, making it effectively inherited, contrary to the intent of _N4527_.12.9 [class.inhctor] paragraph 3. std::function is affected by this issue.

A kernel of a resolution might be to inherit the copy and move constructors as deleted. Then they will be more specialized than any template, and the user won't get conversion-from-base behavior unless they explicitly declare it. However, reference binding in overload resolution is a potential gap. Something like b::b( a & ) = delete with a non-const parameter would not add safety if it's not chosen.

See also issue 1941.