Fixing order of operations undefined behavior in reading inheritance