public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Myers <ncm@cygnus.com>
To: egcs@cygnus.com
Subject: Re: Bug in egcs ?
Date: Thu, 23 Apr 1998 21:12:00 -0000	[thread overview]
Message-ID: <353FD1A1.2F66831A@cygnus.com> (raw)
In-Reply-To: <353F3C9D.EDC7B0D8.cygnus.egcs@cern.ch>

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.

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

       reply	other threads:[~1998-04-23 21:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <353F3C9D.EDC7B0D8.cygnus.egcs@cern.ch>
1998-04-23 21:12 ` Nathan Myers [this message]
1998-04-24  6:54   ` Gabriel Dos Reis
1998-04-23  6:05 Laurent Deniau
     [not found] <52lnxmz6px.fsf.cygnus.egcs@ace.funcom.com>
1997-12-15 15:07 ` Bug in egcs? Jason Merrill
1997-12-16  0:36   ` Marius Kjeldahl
1997-12-16 12:25     ` Jason Merrill
1997-12-16 12:25       ` Marius Kjeldahl
  -- strict thread matches above, loose matches on Subject: below --
1997-12-15 12:34 Marius Kjeldahl
1997-12-15 13:47 ` H.J. Lu
1997-12-15 13:58   ` H.J. Lu
1997-12-15 16:57   ` Jani Hakala

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=353FD1A1.2F66831A@cygnus.com \
    --to=ncm@cygnus.com \
    --cc=egcs@cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).