From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nathan Myers To: egcs@cygnus.com Subject: Re: Bug in egcs ? Date: Thu, 23 Apr 1998 21:12:00 -0000 Message-id: <353FD1A1.2F66831A@cygnus.com> References: <353F3C9D.EDC7B0D8.cygnus.egcs@cern.ch> X-SW-Source: 1998-04/msg00965.html Laurent Deniau wrote: > egcs doesn't complain on the following code: > > template > struct Object { > Object& > operator = (Object const& e) { > const_cast(_e) = e; > return *this; > } > T _e; > }; > > According to the CD2, we should have write : > > const_cast(_e) = e; > > in order to get reference to _e. This code is wrong in any case. No cast is needed, generally, to call T::operator= on a const right-operand. (auto_ptr<> is a special case.) In this case, the expression _e already has type T&, because _e is itself not const, so the const_cast has no effect anyway. I don't see how the compiler could be instrumented to detect errors like this. It might be reasonable for the compiler to warn about calling operator= with an rvalue left-operand, and perhaps to warn about a cast that has no effect. Nathan Myers ncm@cantrip.org