For a standard layout class, it is legal to convert a pointer to an object of the class to a pointer to the first non-static data member of the class. Now assume that the first non-static data member happens to be a private member. Is this a legal way to modify a private data member outside class' member function?
If not, could you indicate what part of standard prevents it?
Note: The purpose here is to understand the standard better, not to do this in actual code.
That's fine, if all non-
staticdata members areprivate. From the C++20 final working draft:[basic.compound][class.union]), or[class.mem]), orcsuch thataandcare pointer-interconvertible, andcandbare pointer-interconvertible.11.2 Properties of classes
[class.prop]Sis a standard-layout class if it: