The static assert in the code below fails.
Of course, I know that this is because of the user-provided move constructor in Bar.
#include <type_traits>
using namespace std;
struct Bar
{
public:
Bar() = default;
Bar(const Bar&) = default;
~Bar() = default;
Bar(Bar&&)
{
}
};
struct Foo
{
Bar b;
Foo() = default;
~Foo() = default;
Foo(const Foo&) = default;
Foo(Foo&&) = delete;
Foo & operator= (Foo && ) = delete;
Foo & operator= (const Foo & ) = delete;
};
static_assert(is_trivially_copyable_v<Foo>); // Fails
What I don't understand is how to interpret the standard regarding trivial copyability. From the C++ 17 standard:
A trivially copyable class is a class:
(6.1) where each copy constructor, move constructor, copy assignment operator, and move assignment operator ([class.copy], [over.ass]) is either deleted or trivial,
(6.2) that has at least one non-deleted copy constructor, move constructor, copy assignment operator, or move assignment operator, and
(6.3) that has a trivial, non-deleted destructor.
It seems to me the Foo meets these criteria:
6.1: They're all deleted except the copy constructor which is trivial. Bar also has a trivial copy constuctor, so that should ensure the Foo copy contructor is truly trivial.
6.2: The defaulted copy constructor
6.3: Foo destructor is defaulted and so is the Bar one, so the destructor should be trivial.
What am I not getting?
By the way I'm not actually trying to do anything apart from better understand the standard.