I created this base class for non-copyable classes:
class non_copyable
{
public:
non_copyable(const non_copyable&) = delete;
non_copyable& operator=(const non_copyable&) = delete;
virtual ~non_copyable() = default;
protected:
non_copyable() = default;
};
Then I created this derived class:
class manager
: public non_copyable
{
public:
manager()
{
}
std::string s;
};
I'm able to create an instance of the class and return it like this:
manager get()
{
return manager();
}
I think this should not be possible, because the copy constructor is deleted and the implicitly generated move constructor is deleted, because there is a user-defined (deleted) copy constructor.
This code compiles with MinGW-64 7.2 but not with MSVC 2017 and yields this message:
function "manager::operator=(const manager &) throw()" (declared implicitly) cannot be referenced -- it is a deleted function
Is this a problem with the compiler, allowed by C++ design or am I doing something wrong?