Title
Ambiguity inheriting constructors with default arguments
Status
cd5
Section
12.2.4.3 [over.ics.rank]
Submitter
Richard Smith

Created on 2016-06-23.00:00:00 last changed 48 months ago

Messages

Date: 2017-07-15.00:00:00

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

Date: 2017-05-15.00:00:00

Proposed resolution (May, 2017):

This issue is resolved by the resolution of issue 2273.

Date: 2018-02-27.00:00:00

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;
History
Date User Action Args
2020-12-15 00:00:00adminsetstatus: drwp -> cd5
2018-02-27 00:00:00adminsetmessages: + msg6147
2018-02-27 00:00:00adminsetmessages: + msg6146
2018-02-27 00:00:00adminsetstatus: open -> drwp
2016-06-23 00:00:00admincreate