In this example, C++17 can construct a Derived class using the Base class's constructor using {}, but not ().
This also works on C++20 for GCC and Clang, but not for MSVC.
Why can I constuct the Derived class this way? Is it safe?
I have looked through the additions and changes in C++17 and can not find what changed to allow this.
It is very possible that I am blind.
#include <iostream>
class Base {
public:
Base(const int value) {
std::cout << "Constructed with value: " << value << '\n';
}
};
class Derived : public Base {
};
int main(){
// does compile on C++17 with MSVC
// does not compile pre or post C++17 with MSVC
// does compile on and post C++17 on GCC and Clang
// does not compile pre C++17 with GCC and Glang
Derived foo{ 42 };
// does not compile on any C++ version with MSVC, GCC or Clang
Derived bar(42);
}