[ub] unions and undefined behavior

Gabriel Dos Reis gdr at cs.tamu.edu
Wed Jul 24 20:21:21 CEST 2013


Jeffrey Yasskin <jyasskin at google.com> writes:

[...]

| However, I agree that this is more subtle than I'm happy with. We
| already have the notion of layout-compatible types, but T and const T
| aren't layout-compatible (C++14[basic.types]p11). What would go wrong
| if we said that cv-qualified versions of T were layout-compatible with
| T?

Good question.  I suspect a dual question worth considering is:  why did
we make T and const T non-layout compatible in the first place?
Was it for aliasing purposes (I'm doubtful)?  Or did we envision the
possibility that an implementation could set a constness bit in
the object (or value) representation?  Just oversight?

-- Gaby


More information about the ub mailing list