The future of C++ alignment: passing by value?

c++, c++11, eigen, memory-alignment

Solution

They could do this in C++11:

class alignas(16) Matrix4f
{
    // ...
};

Now the class will always be aligned on a 16-byte boundary.

Also, maybe I'm being silly but this shouldn't be an issue anyway. Given a class like this:

class Matrix4f
{
public:
    // ...
private:
    // their data type (aligned however they decided in that library):
    aligned_data_type data;

    // or in C++11
    alignas(16) float data[16];
};

Compilers are now obligated to allocate a `Matrix4f` on a 16-byte boundary anyway, because that would break it; the class-level `alignas` should be redundant. But I've been known to be wrong in the past, somehow.

Problem

Reading the Eigen library documentation, I noticed that some objects cannot be passed by value. Are there any developments in C++11 or planned developments that will make it safe to pass such objects by value? Also, why is there no problem with returning such objects by value?

Original source