On 12/18/2017 10:48 AM, Иван Вайгульт wrote:
> Non editorial issue, for sure.
>
> Did I get it right, that was unintended and I can file an issue?
Richard Smith cleaned up the area of "storage" vs. "object" a short while
ago, and while we say that an "object occupies a region of storage" and
"The memory available to a C++ program consists of one or more sequences of
contiguous bytes", we seem to fall short of actually making the storage
for an object viewable as an array of std::byte.
Note that this is a rather tricky area, because changes here might
gravely affect the liberty of optimizers. In particular, we don't
want to have the ability that a pointer to one complete object can
be somehow used to gain access to another (possibly adjacent) complete
object.
In short, I'm not sure about the "unintended" part.
Jens
> On Friday, December 15, 2017 at 4:06:24 PM UTC, Иван Вайгульт wrote:
>
> It is clearly said, that triviality copy copyable object can be copied to an array of chars and back. [basic.types 2 <
http://eel.is/c++draft/basic.types#2>]
>
> It is also allowed to copy one trivially copyable instance to another. [basic.types.3 <
http://eel.is/c++draft/basic.types#3>]
>
>
> Representation of an object is said to be sequence of unsigned chars [basic.types.6.7 <
http://eel.is/c++draft/basic#types-4>]
>
>
> The standard allows to create an instance of object reusing char array [basic.memobj.3 <
http://eel.is/c++draft/basic.memobj#intro.object-3>]
>
>
> Aliasing an object instance with char is allowed by [expr.basic.lval.11 <
http://eel.is/c++draft/expr#basic.lval-11>]
>
>
> But all of this doesn't imply that I can:
>
>
> ||
> MyStructs ={};
> char*begin=(char*)&s;
> char*end=begin+sizeof(MyStruct);
> for(char*it =begin;it !=end;++it){
> //do something with it here
> }
>
> Because it is not said anywhere directly or indirectly that this memory is consequent and can be viewed as char[sizeof(MyStruct)].
>
>
> Moreover, it is unclear how to write a procedure that copies object representation to an array.
>
>
> Am I missing something? Was that intended? If so, what's the profit from char aliasing if it cannot be used.
>
>
> Thanks,
>
> Ivan
>