Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the aliasing loophole apply to signed characters?

In C++ there is an aliasing loophole which allows the object representation of any object to be read or written through some pointers of character type.

Does this apply only to char and unsigned char or also to signed char?

like image 396
BeeOnRope Avatar asked Aug 26 '19 07:08

BeeOnRope


1 Answers

No, the provision does not extend to signed char.

[basic.lval]

8 If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined:

  • [...]
  • a char, unsigned char, or std​::​byte type.

The quote above contains the very last bullet that pertains to aliasing with character types. signed char is excluded.

Nevertheless, this is also part of the subject CWG Issue 350 deals with, and so may change. Given the direction the issue has taken, the intent is for it to be (eventually, hopefully?) well-defined.

like image 147
StoryTeller - Unslander Monica Avatar answered Oct 23 '22 05:10

StoryTeller - Unslander Monica