Section: 23.2.7.1 [associative.reqmts.general], 23.2.8.1 [unord.req.general] Status: New Submitter: Jens Maurer Opened: 2022-04-19 Last modified: 2022-05-17
Priority: 3
View other active issues in [associative.reqmts.general].
View all other issues in [associative.reqmts.general].
View all issues with New status.
Discussion:
Keys for elements of associative containers are presented as const
subobjects,
preventing their modification by user code according to 9.2.9.2 [dcl.type.cv] p4.
std::map<int, int> map; map.emplace(1, 2); using KT = std::map<int, int>::key_type; auto it = map.begin(); it->first.~KT(); new (const_cast<int*>(&it->first)) KT(3);
This, of course, breaks the ordering of the keys, and should be undefined behavior.
Related issue: CWG 2514.[2022-05-17; Reflector poll]
Set priority to 3 after reflector poll. One vote for NAD.
Proposed resolution:
This wording is relative to N4910.
Modify 23.2.7.1 [associative.reqmts.general] as indicated:
-5- For
set
andmultiset
the value type is the same as the key type. Formap
andmultimap
it is equal topair<const Key, T>
. Ending the lifetime of the key subobject of a container element by means other than invoking a member function of the container results in undefined behavior.
Modify 23.2.8.1 [unord.req.general] as indicated:
-7- For
unordered_set
andunordered_multiset
the value type is the same as the key type. Forunordered_map
andunordered_multimap
it ispair<const Key, T>
. Ending the lifetime of the key subobject of a container element by means other than invoking a member function of the container results in undefined behavior.