C++ Logo

sg12

Advanced search

Re: [ub] unions and undefined behavior

From: Gabriel Dos Reis <gdr_at_[hidden]>
Date: Wed, 24 Jul 2013 13:21:21 -0500
Jeffrey Yasskin <jyasskin_at_[hidden]> 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

Received on 2013-07-24 20:21:37