Executing the following code:
#include <iostream>
#include <type_traits>
struct s_ref {
int &foo;
};
struct s_ptr {
int *foo;
};
int main(int argc, char *argv[])
{
std::cout << "s_ref is_standard_layout:" << std::is_standard_layout<struct s_ref>::value << std::endl;
std::cout << "s_ptr is_standard_layout:" << std::is_standard_layout<struct s_ptr>::value << std::endl;
return 0;
}
results in:
s_ref is_standard_layout:0
s_ptr is_standard_layout:1
Based on the uses of standard layout (i.e.: "Standard layout types are useful for communicating with code written in other programming languages") this makes sense, but I'm not sure which is the rule that is violated:
A standard-layout class is a class (defined with class, struct or union) that:
has no virtual functions and no virtual base classes.
has the same access control (private, protected, public) for all its non-static data members.
either has no non-static data members in the most derived class and at most one base class with non-static data members, or has no base classes with non-static data members.
its base class (if any) is itself also a standard-layout class.
And, has no base classes of the same type as its first non-static data member.
Edit: the quote is from: http://www.cplusplus.com/reference/type_traits/is_standard_layout/, but http://en.cppreference.com/w/cpp/concept/StandardLayoutType is also similar.