Why is the move constructor for Base
mandatory in case of inheritance (class B
) in the following code (both in gcc 7.2 and clang 4.0)? I would expect it not to be required with guaranteed copy elision in C++17, as in case of composition (class A
).
struct Base {
Base(Base&&) = delete;
Base& operator=(Base&&) = delete;
Base()
{
}
};
Base make_base()
{
return Base{};
}
struct A {
A() : b(make_base()) {} // <<<--- compiles fine
Base b;
};
#ifdef FAIL
struct B : public Base {
B() : Base(make_base()) {} // <<<--- "Base(Base&&) is deleted"
};
#endif
#include <tuple>
doing there? – Arvad#include <tuple>
(it was a leftover from another example). – RorryBase
as non-movable but operation involving movement does not yield compile time error in case of composition. – Generatrixstd::make_from_tuple
en.cppreference.com/w/cpp/utility/make_from_tupleT
doesn't have to be movable. – Rorrystd::make_from_tuple
to work" means that "std::make_from_tuple
should work for non-movable types". – Rorryb(make_base())
is an invocation of move constructor that gets properly recognized and omitted due to copy elision. And I'm not arguing that "make_from_tuple should work for non-movable types". – Generatrix