Boost logo

Boost :

Subject: [boost] [move] auto-generated operator=
From: Jeffrey Hellrung (jhellrung_at_[hidden])
Date: 2009-09-03 02:55:02

Hi (again) Ion,

I recently ran into the following issue. I defined a
copyable-and-movable class X, and class Y has a member variable of type
X and no other member variables. It thus (apparently) happens that Y's
auto-generated operator= takes a non-const reference to Y, which I would
guess is generally not desired, or at least an operator= overload taking
a const reference to Y should be available.

For whatever reason, MSVC9 didn't complain at all about using the
auto-generated operator=, but when a friend tried compiling code with
GCC on Ubuntu, GCC complained about no matching function call to
operator=(const Y) (or something like that). The error occurred within
a concept checking class, and I would've assumed that MSVC9 was looking
at the same code and should've come to the same conclusion; I haven't
investigated this further. In any case, we added a trivial
Y::operator=(const Y&) explicitly, but GCC didn't like this overload,
and it finally quieted down once we added *both* Y::operator=(Y&) and
Y::operator=(const Y&). Unfortunately, MSVC9 gives warnings about
several operator= overloads, so right now we only have those explicit
overloads of operator= when compiling with GCC.

The only point I want to make is that it seems worth mentioning this
subtlety (at least it was a subtlety to me) in the move documentation
somewhere, and perhaps how to most easily and portably address this (I'm
not sure what that would be), as I would expect it to be a not uncommon

- Jeff

Boost list run by bdawes at, gregod at, cpdaniel at, john at