Title
Modifying const subobjects
Status
open
Section
6.7.3 [basic.life]
Submitter
Jiang An

Created on 2021-11-07.00:00:00 last changed 11 months ago

Messages

Date: 2022-11-15.00:00:00

Notes from the November, 2022 meeting

The advice of SG12 is solicited; see cplusplus/papers#1395.

Date: 2021-11-07.00:00:00

The change in C++20 for RU007 allows transparently replacing a const subobject whose complete object is not const, and the new object can be non-const. However, if the reuse of the object has not happened, modifying such subobjects is still undefined behavior.

This restriction causes problems in the implementation of std::map and std::unordered_map; see this bug report. Here, the key_type objects in map containers are const, and implementations generally can't replace these objects after construction.

Perhaps these restrictions can be relaxed to assist in this case: if

  • the complete object of a key_type subobject in a container is not const (as the mapped_type subobject is not const), or

  • the complete object has dynamic storage duration

a const subobject could be modified.

(Is it meaningful to allow a new-expression like new const int(42) to create cv-qualified objects? Perhaps such objects should be unqualified, while maintaining the cv-qualification in the type of the expression?)

History
Date User Action Args
2023-11-09 21:56:10adminsetstatus: review -> open
2022-11-20 07:54:16adminsetmessages: + msg7044
2022-11-20 07:54:16adminsetstatus: open -> review
2021-11-07 00:00:00admincreate