Can I legally reinterpret_cast between standard layouts compatible with layouts?

I am writing a class which, accepting the answer Is the type of enumerated types compatible with their base type? is yes, compatible with struct kevent , but uses enum class es for filter , flags , etc. with the corresponding base types for the corresponding fields. This is also a standard layout (all private fields and all standard layouts by themselves, no virtual elements, no base classes). From my reading of n3690 I can determine that my class and struct kevent have the same representation of values, but I don't see anything in the standard, so I can reinterpret_cast between them, although this seems like a reasonable interpretation of the “value representation”. Is it technically permitted by the standard? If not, what gives you an idea of ​​the value of the type value?

EDIT 2014/02/24 16:45 EST . In response to the comment, I must clarify that I want the reinterpret_cast first class to refer to the second, as, of course, you cannot directly reinterpret_cast use a non-pointer type for another type of non-pointer.

+6
source share
1 answer

but I don’t see anything in the standard, so I can reinterpret_cast between them, although this seems like a reasonable interpretation of “value presentation”. Is it technically permitted by the standard?

No. The standard is clear (see [Basic.lval] p10) about which types can be smoothed out and layout-compatible types are not included.

If not, what gives you an idea of ​​the value of the type value?

If types are trivially copied and have the same value representation, you can memcpy from an object of one type to an object of another type and vice versa. If they cannot be trivially copied, then this gives you nothing at all.

The AFAICT standard does not actually say what can and cannot be done with layout compatible types.

+5
source

All Articles