This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: map<const T, const U> is assignable even though pair<const T, const U> is not


On 23/04/15 11:48 +0100, Jonathan Wakely wrote:
Marshall Clow sent me this problem:

On 22 April 2015 at 21:49, Marshall Clow wrote:
The following code fails to compile w/libc++, but succeeds with
libstdc++.

#include <map>

int main () {
std::map<const int, const int> foo1, foo2;
foo2 = foo1;
}

assigning a allocator-aware container requires that the value type
be
CopyAssignable, which pair<const int, const int> is definitely not.


I think this is a consequence of our optimization to recycle nodes on
assignment, which runs a destructor and then constructs a new element
with placement new, so it doesn't actually do any assignments.

The example violates the preconditions on the assignment, so it's
undefined behaviour, but it's a bit surprising that it Just Works.

Do we want to make this type non-CopyAssignable?

Answering myself ... I don't think we should change anything, given
that pair<const T, U> is already not assignable, and we have to make
map<T, U> assignable despite that.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]