[PATCH] D46845: [libcxx][c++17] P0083R5: Splicing Maps and Sets

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 15 10:46:18 PDT 2018


rsmith added a comment.

In https://reviews.llvm.org/D46845#1099732, @mclow.lists wrote:

> >> One way we could deal with this is by adding an attribute to the compiler to indicate "the const is a lie", that we can apply to std::pair::first, with the semantics being that a top-level const is ignored when determining the "real" type of the member (and so mutating the member after a const_cast has defined behavior). This would apply to all std::pairs, not just the node_handle case, but in practice we don't optimize on the basis of a member being declared const *anyway*, so this isn't such a big deal right now.
> > 
> > I'm a fan of this idea, this would also have the bonus of fixing some pre-existing type-punning between pair<const K, V> and pair<K, V> (see __hash_value_type and __value_type in <unordered_map> and <map>).
>
> This was //supposed// to be taken care of by [class.mem]/21 (common initial sequence), but that foundered on "standard-layout".


Also, the common initial sequence rule only allows loads through the wrong type, not stores, and in any case does not alter the rule that modifying a const object results in UB.


https://reviews.llvm.org/D46845





More information about the cfe-commits mailing list