Standard-layout class describes a standard layout class that:
- has no non-static data members of type non-standard-layout class (or array of such types) or reference,
- has no virtual functions and no virtual base classes,
- has the same access control for all non-static data members,
- has no non-standard-layout base classes,
- has all non-static data members and bit-fields in the class and its base classes first declared in the same class, and given the class as S, has no element of the set M(S) of types as a base class, where M(X) for a type X is defined as:
- If X is a non-union class type with no (possibly inherited) non-static data members, the set M(X) is empty.
- If X is a non-union class type whose first non-static data member has type X0 (where said member may be an anonymous union), the set M(X) consists of X0 and the elements of M(X0).
- If X is a union type, the set M(X) is the union of all M(Ui) and the set containing all Ui, where each Ui is the type of the ith non-static data member of X.
- If X is an array type with element type Xe, the set M(X) consists of Xe and the elements of M(Xe).
- If X is a non-class, non-array type, the set M(X) is empty.
(numbered for convivence)
However, the following fails:
#include <type_traits>
struct A {
int a;
};
struct B : A {
int b;
};
static_assert(std::is_standard_layout<A>::value, "not standard layout"); // succeeds
static_assert(std::is_standard_layout<B>::value, "not standard layout"); // fails
I see that 1-4 are true, so is one of points under 5 false? I find the points under 5 a little confusing.
Aucun commentaire:
Enregistrer un commentaire