Bug in egcs ?
Gabriel Dos Reis
Gabriel.Dos-Reis@dptmaths.ens-cachan.fr
Fri Apr 24 06:54:00 GMT 1998
>>>>> ëNathanû, Nathan Myers <ncm@cygnus.com> wrote:
Nathan> Laurent Deniau wrote:
>> egcs doesn't complain on the following code:
>>
>> template <typename T>
>> struct Object {
>> Object&
>> operator = (Object<T> const& e) {
>> const_cast<T>(_e) = e;
>> return *this;
>> }
>> T _e;
>> };
>>
>> According to the CD2, we should have write :
>>
>> const_cast<T&>(_e) = e;
>>
>> in order to get reference to _e.
Nathan> This code is wrong in any case.
Nathan> No cast is needed, generally, to call T::operator= on a
Nathan> const right-operand. (auto_ptr<> is a special case.)
Nathan> In this case, the expression _e already has type T&, because
In fact in Laurent's former code _e was of type const T (as he told
me). So const_cast<T> (_e) returned an rvalue... And EGCS didn't issue
any diagnostic. I think it should have complained.
-- Gaby
More information about the Gcc
mailing list