public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/16982] New: wrong copy ctor called
@ 2004-08-11 15:42 boris at kolpackov dot net
  2004-08-11 16:21 ` [Bug c++/16982] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: boris at kolpackov dot net @ 2004-08-11 15:42 UTC (permalink / raw)
  To: gcc-bugs

$ cat >test.cxx
extern "C" void
abort ();

struct base
{
  base ()
  {
  }
  
  base (base const&)
  {
    abort ();
  }
};

struct derived : base
{
  derived ()
  {
  }
  
  derived (derived const&)
      : base ()
  {
  }
};


struct s
{
  operator derived ()
  {
    return derived ();
  }
};

int
main ()
{
  s s;

  base const& b (s);
}

$ g++-3.4 --version
g++-3.4 (GCC) 3.4.1 (Debian 3.4.1-5)
$ g++-3.4 test.cxx
$ ./a.out
Aborted

$ g++-3.3 --version
g++-3.3 (GCC) 3.3.4 (Debian 1:3.3.4-7)
$ g++-3.3 test.cxx
$ ./a.out
Aborted

Here is a quote from 8.5.3/5 bullet 2, sub-bullet 1, sub-sub-bullet 2:

  A temporary of type  cv1 T2  [sic] is created, and a constructor is called to
copy the entire rvalue object into the temporary. The reference is bound to the
temporary or to a subobject within the temporary. 

  The constructor that would be used to make the copy shall be callable whether
or not the copy is actually done. 

  [Example: 

   struct A { }; 
   struct B : public A { } b; 
   extern B f();
   const A& rca = f(); // Either bound to the A subobject of the B rvalue,
                       // or the entire B object is copied and the reference
                       // is bound to the A subobject of the copy
  --end example]

-- 
           Summary: wrong copy ctor called
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: boris at kolpackov dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16982


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-08-11 18:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-11 15:42 [Bug c++/16982] New: wrong copy ctor called boris at kolpackov dot net
2004-08-11 16:21 ` [Bug c++/16982] " pinskia at gcc dot gnu dot org
2004-08-11 16:31 ` boris at kolpackov dot net
2004-08-11 18:12 ` bangerth at dealii dot org

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).