Re: user-defined op= for type with reference member
On Jun 11, 10:57 pm, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
Paul Bibbings wrote:
[...]
It is undefined behavior according to [3.8/7, item 3], which requires:
...
the type of the original object is not const-qualified, and, if a class
type, does not contain any non-static data member whose type is const-
qualified or a reference type,
...
I wonder if this text was present in the original version of the
standard. I seem to recall this being legal. (I know that
there was some discussion of it in the committee at the time.)
Since AType contains a non-static reference member, the trick
does not work for AType. Note that in the example in the
standard, there is no non-static reference member.
I know: it's a bummer since classes with reference members are
about the only cases, where one might even consider this
trickery (which is poor form anyway).
The real motivation for the idiom is handling assignment of
virtual base classes correctly. The real problem is that the
idiom doesn't work when inheritance is involved, which makes it
pretty useless for the only real motivation. And of course,
since assignment and inheritance don't work well together
anyway, the fact that assignment is particularly difficult to
get right when virtual base classes are involved isn't really an
issue.
--
James Kanze