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

2024-10-26


2277. Ambiguity inheriting constructors with default arguments

Section: 12.2.4.3  [over.ics.rank]     Status: CD5     Submitter: Richard Smith     Date: 2016-06-23

[Voted into the WP at the July, 2017 meeting.]

In an example like:

  struct A {
    A(int, int = 0);
    void f(int, int = 0);
  };
  struct B : A {
    B(int); using A::A;
    void f(int); using A::f;
  }

calls to B(int) and B::f(int) are ambiguous, because they could equally call the version inherited from the base class. This doesn't match the intent in 9.9 [namespace.udecl], which usually makes derived-class functions take precedence over ones from a base class.

The above patterns are not common, although they sometimes cause breakage when refactoring a base class. However, P0136R1 brings this into sharp focus, because it causes the rejection of the following formerly-valid and very reasonable code:

  struct A {
    A(int = 0);
  };
  struct B : A {
    using B::B;
  };
  B b;

Proposed resolution (May, 2017):

This issue is resolved by the resolution of issue 2273.