1

In the release notes of the latest Visual Studio update (15.7), Microsoft states (9th bullet point):

Inheriting a constructor now works the same as inheriting any other base class member. Previously, this worked by declaring a new constructor that delegates to the original; with this change, base class constructors are visible in a derived class as if they were derived class constructors, improving consistency in C++.

I'm slightly confused what that point actually means.

AFAIK, constructor inheritance requires an explicit using BaseClass::BaseClass; (since C++11):

struct Base
{
    Base() = default;
    Base(int x) : x(x) {}

    int x;
};

struct Derivative : Base
{
    using Base::Base;
    Derivative(int x, int y) : Base(x), y(y) {}

    int y;
};

void main()
{
    Derivative x(10);  // this is ok
}

My understanding of the quote is, that MS allows the constructor inheritance without the need of using BaseClass::BaseClass;. But testing the following code after applying the update doesn't seem to change anything in those regards:

struct Base
{
    Base() = default;
    Base(int x) : x(x) {}

    int x;
};

struct Derivative : Base
{   
    int y{};
};

void main()
{
    Derivative x(10);  // still illegal, compiler error
}

My questions are:

  • What does the quote actually mean? What changed?
  • How does this improve consistency in C++ (AFAIK, the standard didn't change anything in terms of ctor inheritance)?
Timo
  • 9,269
  • 2
  • 28
  • 58
  • To me it reads as `using BaseClass::BaseClass;` now actually works in MSVS. Unfortunately I don't have an older version I can test to see if it didn't. – NathanOliver May 07 '18 at 21:15
  • @NathanOliver I thought about that aswell, but it did work before afaik (I'm pretty sure I already used it before). [Compiler explorer](https://godbolt.org/g/Kt8HJ8) says it's ok and I don't think that cl is updated to the latest version as of right now. – Timo May 07 '18 at 21:16
  • 1
    I think they are saying that they used to implement `using Base::Base;` by synthesizing `Derivative(int z) : Base(z) {}` constructor, but now they call `Base` constructor directly. I guess the difference is detectable by some sufficiently arcane code. – Igor Tandetnik May 08 '18 at 00:55
  • The inheriting constructor syntax has worked since VS 2015. I interpret this the same way as @IgorTandetnik. – Jack C. May 08 '18 at 01:40
  • 2
    The [Visual C++ Team blog](https://blogs.msdn.microsoft.com/vcblog/2018/05/07/announcing-msvc-conforms-to-the-c-standard/) has a post about conformance, and this issue links to this [C++17 Standards working paper](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0136r1.html) which details the issue. – Chuck Walbourn May 08 '18 at 04:56

0 Answers0